Fix for Flac to work with 24bit files (thanks to Play).
Updated COMPILE instructions to avoid confusion about scripts directory.CQTexperiment
parent
3283a97e20
commit
53abdde705
4
COMPILE
4
COMPILE
|
@ -1,5 +1,5 @@
|
||||||
To compile Cog, you must first compile all of the projects in the Frameworks and Preferences folders with the Release build configuration.
|
To compile Cog, you must first compile all of the projects in the Frameworks, Plugins, and Preferences folders with the Release build configuration.
|
||||||
|
|
||||||
To make this easier, I have created a bash script named build_dependencies.sh in the Scripts folder. Just run that in a terminal from the project root, and when it is finished, all the dependencies should be built.
|
To make this easier, I have created a bash script named build_dependencies.sh in the Scripts folder. Just run that in a terminal from the project root (./Scripts/build_dependencies.sh). When it is finished, all the dependencies should be built.
|
||||||
|
|
||||||
If you have any problems, email me at vspader@users.sourceforge.net
|
If you have any problems, email me at vspader@users.sourceforge.net
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
@interface FlacDecoder : NSObject <CogDecoder>
|
@interface FlacDecoder : NSObject <CogDecoder>
|
||||||
{
|
{
|
||||||
FLAC__FileDecoder *decoder;
|
FLAC__FileDecoder *decoder;
|
||||||
char buffer[SAMPLE_BUFFER_SIZE];
|
void *buffer;
|
||||||
int bufferAmount;
|
int bufferAmount;
|
||||||
|
|
||||||
int bitsPerSample;
|
int bitsPerSample;
|
||||||
|
|
|
@ -14,23 +14,65 @@
|
||||||
FLAC__StreamDecoderWriteStatus WriteProc(const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const sampleBuffer[], void *client_data)
|
FLAC__StreamDecoderWriteStatus WriteProc(const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const sampleBuffer[], void *client_data)
|
||||||
{
|
{
|
||||||
FlacDecoder *flacDecoder = (FlacDecoder *)client_data;
|
FlacDecoder *flacDecoder = (FlacDecoder *)client_data;
|
||||||
unsigned wide_samples = frame->header.blocksize;
|
|
||||||
unsigned channels = frame->header.channels;
|
|
||||||
|
|
||||||
UInt16 *buffer = (UInt16 *)[flacDecoder buffer];
|
void *buffer = [flacDecoder buffer];
|
||||||
int i, j, c;
|
|
||||||
|
|
||||||
for (i = j = 0; i < wide_samples; i++)
|
int8_t *alias8;
|
||||||
{
|
int16_t *alias16;
|
||||||
for (c = 0; c < channels; c++, j++)
|
int32_t *alias32;
|
||||||
{
|
int sample, channel;
|
||||||
// buffer[j] = CFSwapInt16LittleToHost(sampleBuffer[c][i]);
|
int32_t audioSample;
|
||||||
buffer[j] = sampleBuffer[c][i];
|
|
||||||
}
|
switch(frame->header.bits_per_sample) {
|
||||||
|
case 8:
|
||||||
|
// Interleave the audio (no need for byte swapping)
|
||||||
|
alias8 = buffer;
|
||||||
|
for(sample = 0; sample < frame->header.blocksize; ++sample) {
|
||||||
|
for(channel = 0; channel < frame->header.channels; ++channel) {
|
||||||
|
*alias8++ = (int8_t)sampleBuffer[channel][sample];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 16:
|
||||||
|
// Interleave the audio, converting to big endian byte order
|
||||||
|
alias16 = buffer;
|
||||||
|
for(sample = 0; sample < frame->header.blocksize; ++sample) {
|
||||||
|
for(channel = 0; channel < frame->header.channels; ++channel) {
|
||||||
|
*alias16++ = (int16_t)OSSwapHostToBigInt16((int16_t)sampleBuffer[channel][sample]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 24:
|
||||||
|
// Interleave the audio (no need for byte swapping)
|
||||||
|
alias8 = buffer;
|
||||||
|
for(sample = 0; sample < frame->header.blocksize; ++sample) {
|
||||||
|
for(channel = 0; channel < frame->header.channels; ++channel) {
|
||||||
|
audioSample = sampleBuffer[channel][sample];
|
||||||
|
*alias8++ = (int8_t)(audioSample >> 16);
|
||||||
|
*alias8++ = (int8_t)(audioSample >> 8);
|
||||||
|
*alias8++ = (int8_t)audioSample;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 32:
|
||||||
|
// Interleave the audio, converting to big endian byte order
|
||||||
|
alias32 = buffer;
|
||||||
|
for(sample = 0; sample < frame->header.blocksize; ++sample) {
|
||||||
|
for(channel = 0; channel < frame->header.channels; ++channel) {
|
||||||
|
*alias32++ = OSSwapHostToBigInt32(sampleBuffer[channel][sample]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
NSLog(@"Error, unsupported sample size.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// memcpy([flacDecoder buffer], sampleBuffer, wide_samples*[flacDecoder bitsPerSample]/8);
|
[flacDecoder setBufferAmount:frame->header.blocksize * frame->header.channels * (frame->header.bits_per_sample/8)];
|
||||||
[flacDecoder setBufferAmount:(wide_samples * channels*2)];
|
|
||||||
|
|
||||||
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
|
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
|
||||||
}
|
}
|
||||||
|
@ -84,6 +126,8 @@ void ErrorProc(const FLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus
|
||||||
|
|
||||||
FLAC__file_decoder_process_until_end_of_metadata(decoder);
|
FLAC__file_decoder_process_until_end_of_metadata(decoder);
|
||||||
|
|
||||||
|
buffer = malloc(SAMPLE_BUFFER_SIZE);
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +161,7 @@ void ErrorProc(const FLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus
|
||||||
bufferAmount -= count;
|
bufferAmount -= count;
|
||||||
|
|
||||||
if (bufferAmount > 0)
|
if (bufferAmount > 0)
|
||||||
memmove(buffer, &buffer[count], bufferAmount);
|
memmove((char *)buffer, &((char *)buffer)[count], bufferAmount);
|
||||||
|
|
||||||
if (count < size)
|
if (count < size)
|
||||||
numread = [self fillBuffer:(&((char *)buf)[count]) ofSize:(size - count)];
|
numread = [self fillBuffer:(&((char *)buf)[count]) ofSize:(size - count)];
|
||||||
|
@ -135,8 +179,13 @@ void ErrorProc(const FLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus
|
||||||
FLAC__file_decoder_finish(decoder);
|
FLAC__file_decoder_finish(decoder);
|
||||||
FLAC__file_decoder_delete(decoder);
|
FLAC__file_decoder_delete(decoder);
|
||||||
}
|
}
|
||||||
|
if (buffer)
|
||||||
|
{
|
||||||
|
free(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
decoder = NULL;
|
decoder = NULL;
|
||||||
|
buffer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (double)seekToTime:(double)milliseconds
|
- (double)seekToTime:(double)milliseconds
|
||||||
|
@ -172,7 +221,7 @@ void ErrorProc(const FLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus
|
||||||
[NSNumber numberWithInt:bitsPerSample],@"bitsPerSample",
|
[NSNumber numberWithInt:bitsPerSample],@"bitsPerSample",
|
||||||
[NSNumber numberWithFloat:frequency],@"sampleRate",
|
[NSNumber numberWithFloat:frequency],@"sampleRate",
|
||||||
[NSNumber numberWithDouble:length],@"length",
|
[NSNumber numberWithDouble:length],@"length",
|
||||||
@"host",@"endian",
|
@"big",@"endian",
|
||||||
nil];
|
nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue