Skip to content

Commit

Permalink
Tidy up with a clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebrady committed Sep 11, 2016
1 parent 6bf0a1d commit 064bd29
Show file tree
Hide file tree
Showing 29 changed files with 2,893 additions and 2,871 deletions.
1,566 changes: 710 additions & 856 deletions alac.c

Large diffs are not rendered by default.

61 changes: 26 additions & 35 deletions alac.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,43 @@
typedef struct alac_file alac_file;

alac_file *alac_create(int samplesize, int numchannels);
void alac_decode_frame(alac_file *alac,
unsigned char *inbuffer,
void *outbuffer, int *outputsize);
void alac_decode_frame(alac_file *alac, unsigned char *inbuffer, void *outbuffer, int *outputsize);
void alac_set_info(alac_file *alac, char *inputbuffer);
void alac_allocate_buffers(alac_file *alac);
void alac_free(alac_file *alac);

struct alac_file
{
unsigned char *input_buffer;
int input_buffer_bitaccumulator; /* used so we can do arbitary
bit reads */
struct alac_file {
unsigned char *input_buffer;
int input_buffer_bitaccumulator; /* used so we can do arbitary
bit reads */

int samplesize;
int numchannels;
int bytespersample;
int samplesize;
int numchannels;
int bytespersample;

/* buffers */
int32_t *predicterror_buffer_a;
int32_t *predicterror_buffer_b;

/* buffers */
int32_t *predicterror_buffer_a;
int32_t *predicterror_buffer_b;

int32_t *outputsamples_buffer_a;
int32_t *outputsamples_buffer_b;

int32_t *uncompressed_bytes_buffer_a;
int32_t *uncompressed_bytes_buffer_b;

int32_t *outputsamples_buffer_a;
int32_t *outputsamples_buffer_b;

int32_t *uncompressed_bytes_buffer_a;
int32_t *uncompressed_bytes_buffer_b;

/* stuff from setinfo */
uint32_t setinfo_max_samples_per_frame; /* 0x1000 = 4096 */ /* max samples per frame? */
uint8_t setinfo_7a; /* 0x00 */
uint8_t setinfo_sample_size; /* 0x10 */
uint8_t setinfo_rice_historymult; /* 0x28 */
uint8_t setinfo_rice_initialhistory; /* 0x0a */
uint8_t setinfo_rice_kmodifier; /* 0x0e */
uint8_t setinfo_7f; /* 0x02 */
uint16_t setinfo_80; /* 0x00ff */
uint32_t setinfo_82; /* 0x000020e7 */ /* max sample size?? */
uint32_t setinfo_86; /* 0x00069fe4 */ /* bit rate (avarge)?? */
uint32_t setinfo_8a_rate; /* 0x0000ac44 */
uint32_t setinfo_max_samples_per_frame; /* 0x1000 = 4096 */ /* max samples per frame? */
uint8_t setinfo_7a; /* 0x00 */
uint8_t setinfo_sample_size; /* 0x10 */
uint8_t setinfo_rice_historymult; /* 0x28 */
uint8_t setinfo_rice_initialhistory; /* 0x0a */
uint8_t setinfo_rice_kmodifier; /* 0x0e */
uint8_t setinfo_7f; /* 0x02 */
uint16_t setinfo_80; /* 0x00ff */
uint32_t setinfo_82; /* 0x000020e7 */ /* max sample size?? */
uint32_t setinfo_86; /* 0x00069fe4 */ /* bit rate (avarge)?? */
uint32_t setinfo_8a_rate; /* 0x0000ac44 */
/* end setinfo stuff */

};


#endif /* __ALAC__DECOMP_H */

49 changes: 24 additions & 25 deletions apple_alac.cpp
Original file line number Diff line number Diff line change
@@ -1,56 +1,55 @@
#include <string.h>

// these are headers for the ALAC decoder, utilities and endian utilities
#include <alac/ALACDecoder.h>
#include <alac/ALACBitUtilities.h>
#include <alac/ALACDecoder.h>
#include <alac/EndianPortable.h>

#include "config.h"
#include "apple_alac.h"
#include "config.h"

typedef struct magicCookie {
ALACSpecificConfig config;
ALACAudioChannelLayout channelLayoutInfo; // seems to be unused
} magicCookie;

magicCookie cookie;
ALACDecoder * theDecoder;
ALACDecoder *theDecoder;

extern "C" int apple_alac_init(int32_t fmtp[12]) {

memset(&cookie,0,sizeof(magicCookie));

//create a magic cookie for the decoder from the fmtp information. It seems to be in the same format as a simple magic cookie

memset(&cookie, 0, sizeof(magicCookie));

// create a magic cookie for the decoder from the fmtp information. It seems to be in the same
// format as a simple magic cookie

cookie.config.frameLength = Swap32NtoB(352);
cookie.config.compatibleVersion = fmtp[2]; // should be zero, uint8_t
cookie.config.bitDepth = fmtp[3]; // uint8_t expected to be 16
cookie.config.pb = fmtp[4]; // uint8_t should be 40;
cookie.config.mb = fmtp[5]; // uint8_t should be 10;
cookie.config.kb = fmtp[6]; // uint8_t should be 14;
cookie.config.numChannels = fmtp[7]; // uint8_t expected to be 2
cookie.config.maxRun = Swap16NtoB(fmtp[8]); // uint16_t expected to be 255
cookie.config.compatibleVersion = fmtp[2]; // should be zero, uint8_t
cookie.config.bitDepth = fmtp[3]; // uint8_t expected to be 16
cookie.config.pb = fmtp[4]; // uint8_t should be 40;
cookie.config.mb = fmtp[5]; // uint8_t should be 10;
cookie.config.kb = fmtp[6]; // uint8_t should be 14;
cookie.config.numChannels = fmtp[7]; // uint8_t expected to be 2
cookie.config.maxRun = Swap16NtoB(fmtp[8]); // uint16_t expected to be 255
cookie.config.maxFrameBytes = Swap32NtoB(fmtp[9]); // uint32_t should be 0;
cookie.config.avgBitRate = Swap32NtoB(fmtp[10]); // uint32_t should be 0;;
cookie.config.sampleRate = Swap32NtoB(fmtp[11]); // uint32_t expected to be 44100;
cookie.config.avgBitRate = Swap32NtoB(fmtp[10]); // uint32_t should be 0;;
cookie.config.sampleRate = Swap32NtoB(fmtp[11]); // uint32_t expected to be 44100;

theDecoder = new ALACDecoder;
theDecoder->Init(&cookie, sizeof(magicCookie));
theDecoder->Init(&cookie, sizeof(magicCookie));

return 0;
}

extern "C" int apple_alac_decode_frame(unsigned char *sampleBuffer, uint32_t bufferLength, unsigned char *dest, int *outsize)
{
extern "C" int apple_alac_decode_frame(unsigned char *sampleBuffer, uint32_t bufferLength,
unsigned char *dest, int *outsize) {
uint32_t numFrames = 0;
BitBuffer theInputBuffer;
BitBufferInit(&theInputBuffer, sampleBuffer, bufferLength);
theDecoder->Decode(&theInputBuffer, dest, Swap32BtoN(cookie.config.frameLength), cookie.config.numChannels, &numFrames);
theDecoder->Decode(&theInputBuffer, dest, Swap32BtoN(cookie.config.frameLength),
cookie.config.numChannels, &numFrames);
*outsize = numFrames;
return 0;
}

extern "C" int apple_alac_terminate() {
delete(theDecoder);
}

extern "C" int apple_alac_terminate() { delete (theDecoder); }
11 changes: 5 additions & 6 deletions apple_alac.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
#ifndef __APPLE_ALAC_H
#define __APPLE_ALAC_H

#include <stdint.h>
#include "config.h"
#include <stdint.h>

#ifdef __cplusplus
#define EXTERNC extern "C"
#define EXTERNC extern "C"
#else
#define EXTERNC
#define EXTERNC
#endif


EXTERNC int apple_alac_init(int32_t fmtp[12]);
EXTERNC int apple_alac_terminate();
EXTERNC int apple_alac_decode_frame(unsigned char *sampleBuffer, uint32_t bufferLength, unsigned char *dest, int *outsize);
EXTERNC int apple_alac_decode_frame(unsigned char *sampleBuffer, uint32_t bufferLength,
unsigned char *dest, int *outsize);

#undef EXTERNC

#endif /* __APPLE_ALAC_H */

6 changes: 3 additions & 3 deletions audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/

#include <stdio.h>
#include <string.h>
#include "audio.h"
#include "config.h"
#include <stdio.h>
#include <string.h>

#ifdef CONFIG_SNDIO
extern audio_output audio_sndio;
Expand Down Expand Up @@ -67,7 +67,7 @@ static audio_output *outputs[] = {
#ifdef CONFIG_DUMMY
&audio_dummy,
#endif
#ifdef CONFIG_PIPE
#ifdef CONFIG_PIPE
&audio_pipe,
#endif
#ifdef CONFIG_STDOUT
Expand Down
8 changes: 4 additions & 4 deletions audio.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef _AUDIO_H
#define _AUDIO_H

#include <stdint.h>
#include <libconfig.h>
#include <stdint.h>

typedef struct {
double current_volume_dB;
Expand Down Expand Up @@ -32,17 +32,17 @@ typedef struct {
// almost certainly wrong if the buffer is empty, so put silent buffers into it to make it busy.
// will change dynamically, so keep watching it. Implemented in ALSA only.
// returns a negative error code if there's a problem
int (*delay)(long* the_delay); // snd_pcm_sframes_t is a signed long
int (*delay)(long *the_delay); // snd_pcm_sframes_t is a signed long

// may be NULL, in which case soft volume is applied
void (*volume)(double vol);

// may be NULL, in which case soft volume parameters are used
void (*parameters)(audio_parameters *info);

// may be NULL, in which case software muting is used.
void (*mute)(int do_mute);

} audio_output;

audio_output *audio_get_output(char *name);
Expand Down
Loading

0 comments on commit 064bd29

Please sign in to comment.