Updated Musepack plugin to use new decoder protocol.
parent
9b05ce02d2
commit
ecf7f30fb4
|
@ -8,8 +8,8 @@
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
1703330D0B8FB64500327265 /* MusepackDecoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 1703330A0B8FB64500327265 /* MusepackDecoder.m */; };
|
1703330D0B8FB64500327265 /* MusepackDecoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 1703330A0B8FB64500327265 /* MusepackDecoder.m */; };
|
||||||
17F564B40C3BDD970019975C /* MPCDec.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 17F5625F0C3BD97C0019975C /* MPCDec.framework */; };
|
17F564B40C3BDD970019975C /* mpcdec.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 17F5625F0C3BD97C0019975C /* mpcdec.framework */; };
|
||||||
17F564B70C3BDD990019975C /* MPCDec.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 17F5625F0C3BD97C0019975C /* MPCDec.framework */; };
|
17F564B70C3BDD990019975C /* mpcdec.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 17F5625F0C3BD97C0019975C /* mpcdec.framework */; };
|
||||||
8D5B49B4048680CD000E48DA /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */; };
|
8D5B49B4048680CD000E48DA /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */; };
|
||||||
8E2B8B4B0B9B48D000F2D9E8 /* Plugin.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 8E2B8B4A0B9B48D000F2D9E8 /* Plugin.h */; };
|
8E2B8B4B0B9B48D000F2D9E8 /* Plugin.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 8E2B8B4A0B9B48D000F2D9E8 /* Plugin.h */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
@ -38,7 +38,7 @@
|
||||||
dstPath = "";
|
dstPath = "";
|
||||||
dstSubfolderSpec = 10;
|
dstSubfolderSpec = 10;
|
||||||
files = (
|
files = (
|
||||||
17F564B70C3BDD990019975C /* MPCDec.framework in CopyFiles */,
|
17F564B70C3BDD990019975C /* mpcdec.framework in CopyFiles */,
|
||||||
8E2B8B4B0B9B48D000F2D9E8 /* Plugin.h in CopyFiles */,
|
8E2B8B4B0B9B48D000F2D9E8 /* Plugin.h in CopyFiles */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
@ -64,7 +64,7 @@
|
||||||
isa = PBXFrameworksBuildPhase;
|
isa = PBXFrameworksBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
17F564B40C3BDD970019975C /* MPCDec.framework in Frameworks */,
|
17F564B40C3BDD970019975C /* mpcdec.framework in Frameworks */,
|
||||||
8D5B49B4048680CD000E48DA /* Cocoa.framework in Frameworks */,
|
8D5B49B4048680CD000E48DA /* Cocoa.framework in Frameworks */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
@ -133,7 +133,7 @@
|
||||||
17F562580C3BD97B0019975C /* Products */ = {
|
17F562580C3BD97B0019975C /* Products */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
17F5625F0C3BD97C0019975C /* MPCDec.framework */,
|
17F5625F0C3BD97C0019975C /* mpcdec.framework */,
|
||||||
);
|
);
|
||||||
name = Products;
|
name = Products;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
@ -201,10 +201,10 @@
|
||||||
/* End PBXProject section */
|
/* End PBXProject section */
|
||||||
|
|
||||||
/* Begin PBXReferenceProxy section */
|
/* Begin PBXReferenceProxy section */
|
||||||
17F5625F0C3BD97C0019975C /* MPCDec.framework */ = {
|
17F5625F0C3BD97C0019975C /* mpcdec.framework */ = {
|
||||||
isa = PBXReferenceProxy;
|
isa = PBXReferenceProxy;
|
||||||
fileType = wrapper.framework;
|
fileType = wrapper.framework;
|
||||||
path = MPCDec.framework;
|
path = mpcdec.framework;
|
||||||
remoteRef = 17F5625E0C3BD97C0019975C /* PBXContainerItemProxy */;
|
remoteRef = 17F5625E0C3BD97C0019975C /* PBXContainerItemProxy */;
|
||||||
sourceTree = BUILT_PRODUCTS_DIR;
|
sourceTree = BUILT_PRODUCTS_DIR;
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,13 +18,13 @@
|
||||||
mpc_reader reader;
|
mpc_reader reader;
|
||||||
|
|
||||||
char buffer[MPC_FRAME_LENGTH*4];
|
char buffer[MPC_FRAME_LENGTH*4];
|
||||||
int bufferAmount;
|
int bufferFrames;
|
||||||
|
|
||||||
int bitrate;
|
int bitrate;
|
||||||
float frequency;
|
float frequency;
|
||||||
double length;
|
long totalFrames;
|
||||||
}
|
}
|
||||||
- (BOOL)writeSamplesToBuffer:(uint16_t *)sample_buffer fromBuffer:(const MPC_SAMPLE_FORMAT *)p_buffer ofSize:(unsigned)p_size;
|
- (BOOL)writeToBuffer:(uint16_t *)sample_buffer fromBuffer:(const MPC_SAMPLE_FORMAT *)p_buffer frames:(unsigned)frames;
|
||||||
|
|
||||||
- (void)setSource:(id<CogSource>)s;
|
- (void)setSource:(id<CogSource>)s;
|
||||||
- (id<CogSource>)source;
|
- (id<CogSource>)source;
|
||||||
|
|
|
@ -87,7 +87,7 @@ mpc_bool_t CanSeekProc(void *data)
|
||||||
bitrate = (int)(info.average_bitrate/1000.0);
|
bitrate = (int)(info.average_bitrate/1000.0);
|
||||||
frequency = info.sample_freq;
|
frequency = info.sample_freq;
|
||||||
|
|
||||||
length = ((double)mpc_streaminfo_get_length_samples(&info)*1000.0)/frequency;
|
totalFrames = mpc_streaminfo_get_length_samples(&info);
|
||||||
|
|
||||||
[self willChangeValueForKey:@"properties"];
|
[self willChangeValueForKey:@"properties"];
|
||||||
[self didChangeValueForKey:@"properties"];
|
[self didChangeValueForKey:@"properties"];
|
||||||
|
@ -95,7 +95,7 @@ mpc_bool_t CanSeekProc(void *data)
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)writeSamplesToBuffer:(uint16_t *)sample_buffer fromBuffer:(const MPC_SAMPLE_FORMAT *)p_buffer ofSize:(unsigned)p_size
|
- (BOOL)writeToBuffer:(uint16_t *)sample_buffer fromBuffer:(const MPC_SAMPLE_FORMAT *)p_buffer frames:(unsigned)frames
|
||||||
{
|
{
|
||||||
unsigned n;
|
unsigned n;
|
||||||
int m_bps = 16;
|
int m_bps = 16;
|
||||||
|
@ -103,6 +103,8 @@ mpc_bool_t CanSeekProc(void *data)
|
||||||
clip_max = (1 << (m_bps - 1)) - 1,
|
clip_max = (1 << (m_bps - 1)) - 1,
|
||||||
float_scale = 1 << (m_bps - 1);
|
float_scale = 1 << (m_bps - 1);
|
||||||
|
|
||||||
|
unsigned p_size = frames * 2; //2 = bits per sample
|
||||||
|
|
||||||
for (n = 0; n < p_size; n++)
|
for (n = 0; n < p_size; n++)
|
||||||
{
|
{
|
||||||
int val;
|
int val;
|
||||||
|
@ -125,18 +127,19 @@ mpc_bool_t CanSeekProc(void *data)
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)fillBuffer:(void *)buf ofSize:(UInt32)size
|
- (int)readAudio:(void *)buf frames:(UInt32)frames
|
||||||
{
|
{
|
||||||
int numread = bufferAmount;
|
|
||||||
int count = 0;
|
|
||||||
MPC_SAMPLE_FORMAT sampleBuffer[MPC_DECODER_BUFFER_LENGTH];
|
MPC_SAMPLE_FORMAT sampleBuffer[MPC_DECODER_BUFFER_LENGTH];
|
||||||
|
|
||||||
//Fill from buffer, going by bufferAmount
|
int framesRead = 0;
|
||||||
|
int bytesPerFrame = 4; //bitsPerSample == 16, channels == 2
|
||||||
|
while (framesRead < frames)
|
||||||
|
{
|
||||||
|
//Fill from buffer, going by bufferFrames
|
||||||
//if still needs more, decode and repeat
|
//if still needs more, decode and repeat
|
||||||
if (bufferAmount == 0)
|
if (bufferFrames == 0)
|
||||||
{
|
{
|
||||||
/* returns the length of the samples*/
|
/* returns the length of the samples*/
|
||||||
|
|
||||||
unsigned status = mpc_decoder_decode(&decoder, sampleBuffer, 0, 0);
|
unsigned status = mpc_decoder_decode(&decoder, sampleBuffer, 0, 0);
|
||||||
if (status == (unsigned)( -1))
|
if (status == (unsigned)( -1))
|
||||||
{
|
{
|
||||||
|
@ -150,31 +153,30 @@ mpc_bool_t CanSeekProc(void *data)
|
||||||
}
|
}
|
||||||
else //status>0 /* status == MPC_FRAME_LENGTH */
|
else //status>0 /* status == MPC_FRAME_LENGTH */
|
||||||
{
|
{
|
||||||
[self writeSamplesToBuffer:((uint16_t*)buffer) fromBuffer:sampleBuffer ofSize:(status*2)];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bufferAmount = status*4;
|
bufferFrames = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
count = bufferAmount;
|
int framesToRead = bufferFrames;
|
||||||
if (bufferAmount > size)
|
if (bufferFrames > frames)
|
||||||
{
|
{
|
||||||
count = size;
|
framesToRead = frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(buf, buffer, count);
|
[self writeToBuffer:((uint16_t*)(buf + (framesRead*bytesPerFrame))) fromBuffer:sampleBuffer frames: bufferFrames];
|
||||||
|
|
||||||
bufferAmount -= count;
|
frames -= framesToRead;
|
||||||
|
framesRead += framesToRead;
|
||||||
|
bufferFrames -= framesToRead;
|
||||||
|
|
||||||
if (bufferAmount > 0)
|
if (bufferFrames > 0)
|
||||||
memmove(buffer, &buffer[count], bufferAmount);
|
{
|
||||||
|
memmove((uint8_t *)sampleBuffer, ((uint8_t *)sampleBuffer) + (framesToRead * bytesPerFrame), bufferFrames * bytesPerFrame);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (count < size)
|
return framesRead;
|
||||||
numread = [self fillBuffer:(&((char *)buf)[count]) ofSize:(size - count)];
|
|
||||||
else
|
|
||||||
numread = 0;
|
|
||||||
|
|
||||||
return count + numread;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)close
|
- (void)close
|
||||||
|
@ -182,11 +184,11 @@ mpc_bool_t CanSeekProc(void *data)
|
||||||
[source close];
|
[source close];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (double)seekToTime:(double)milliseconds
|
- (long)seek:(long)sample
|
||||||
{
|
{
|
||||||
mpc_decoder_seek_sample(&decoder, frequency*((double)milliseconds/1000.0));
|
mpc_decoder_seek_sample(&decoder, sample);
|
||||||
|
|
||||||
return milliseconds;
|
return sample;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setSource:(id<CogSource>)s
|
- (void)setSource:(id<CogSource>)s
|
||||||
|
@ -206,7 +208,7 @@ mpc_bool_t CanSeekProc(void *data)
|
||||||
return [NSDictionary dictionaryWithObjectsAndKeys:
|
return [NSDictionary dictionaryWithObjectsAndKeys:
|
||||||
[NSNumber numberWithInt:bitrate], @"bitrate",
|
[NSNumber numberWithInt:bitrate], @"bitrate",
|
||||||
[NSNumber numberWithFloat:frequency], @"sampleRate",
|
[NSNumber numberWithFloat:frequency], @"sampleRate",
|
||||||
[NSNumber numberWithDouble:length], @"length",
|
[NSNumber numberWithDouble:totalFrames], @"totalFrames",
|
||||||
[NSNumber numberWithInt:16], @"bitsPerSample",
|
[NSNumber numberWithInt:16], @"bitsPerSample",
|
||||||
[NSNumber numberWithInt:2], @"channels",
|
[NSNumber numberWithInt:2], @"channels",
|
||||||
[NSNumber numberWithBool:[source seekable]], @"seekable",
|
[NSNumber numberWithBool:[source seekable]], @"seekable",
|
||||||
|
|
Loading…
Reference in New Issue