Moved Musepack to source system. Fixed MonkeysAudio bug.

CQTexperiment
vspader 2007-03-04 18:41:43 +00:00
parent 505b525d42
commit 53e4ef0c7b
6 changed files with 116 additions and 26 deletions

View File

@ -27,4 +27,7 @@
double length;
}
- (void)setSource:(id<CogSource>)s;
- (id<CogSource>)source;
@end

View File

@ -17,6 +17,8 @@
int n;
sourceIO = new SourceIO(s);
[self setSource:s];
decompress = CreateIAPEDecompressEx(sourceIO, &n);
if (decompress == NULL)
@ -76,6 +78,23 @@
return milliseconds;
}
- (void)setSource:(id<CogSource>)s
{
[s retain];
[source release];
source = s;
}
- (id<CogSource>)source
{
return source;
}
- (BOOL)seekable
{
return [source seekable];
}
- (NSDictionary *)properties
{
return [NSDictionary dictionaryWithObjectsAndKeys:
@ -87,15 +106,10 @@
nil];
}
+ (NSArray *)fileTypes
{
return [NSArray arrayWithObject:@"ape"];
}
- (BOOL)seekable
{
return [source seekable];
}
@end

View File

@ -11,10 +11,10 @@
1745C1A40B90B57400A6768C /* MusepackPropertiesReader.m in Sources */ = {isa = PBXBuildFile; fileRef = 1745C1A20B90B57400A6768C /* MusepackPropertiesReader.m */; };
177FCF280B90C8D00011C3B5 /* MPCDec.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 177FCF270B90C8D00011C3B5 /* MPCDec.framework */; };
177FCF2B0B90C8D20011C3B5 /* MPCDec.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 177FCF270B90C8D00011C3B5 /* MPCDec.framework */; };
177FCF390B90C8F10011C3B5 /* Plugin.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 177FCF380B90C8F10011C3B5 /* Plugin.h */; };
17ADB2020B9793FF00257CA2 /* MusepackPlugin.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 17ADB2000B9793FF00257CA2 /* MusepackPlugin.h */; };
17ADB2030B9793FF00257CA2 /* MusepackPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = 17ADB2010B9793FF00257CA2 /* MusepackPlugin.m */; };
8D5B49B4048680CD000E48DA /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */; };
8E2B8B4B0B9B48D000F2D9E8 /* Plugin.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 8E2B8B4A0B9B48D000F2D9E8 /* Plugin.h */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
@ -25,8 +25,8 @@
dstSubfolderSpec = 10;
files = (
177FCF2B0B90C8D20011C3B5 /* MPCDec.framework in CopyFiles */,
177FCF390B90C8F10011C3B5 /* Plugin.h in CopyFiles */,
17ADB2020B9793FF00257CA2 /* MusepackPlugin.h in CopyFiles */,
8E2B8B4B0B9B48D000F2D9E8 /* Plugin.h in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -41,12 +41,12 @@
1745C1A10B90B57400A6768C /* MusepackPropertiesReader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MusepackPropertiesReader.h; sourceTree = "<group>"; };
1745C1A20B90B57400A6768C /* MusepackPropertiesReader.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = MusepackPropertiesReader.m; sourceTree = "<group>"; };
177FCF270B90C8D00011C3B5 /* MPCDec.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MPCDec.framework; path = ../../Frameworks/MPCDec/build/Release/MPCDec.framework; sourceTree = SOURCE_ROOT; };
177FCF380B90C8F10011C3B5 /* Plugin.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Plugin.h; path = ../../Audio/Plugin.h; sourceTree = SOURCE_ROOT; };
17ADB2000B9793FF00257CA2 /* MusepackPlugin.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MusepackPlugin.h; sourceTree = "<group>"; };
17ADB2010B9793FF00257CA2 /* MusepackPlugin.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = MusepackPlugin.m; sourceTree = "<group>"; };
32DBCF630370AF2F00C91783 /* Musepack_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Musepack_Prefix.pch; sourceTree = "<group>"; };
8D5B49B6048680CD000E48DA /* Musepack.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Musepack.bundle; sourceTree = BUILT_PRODUCTS_DIR; };
8D5B49B7048680CD000E48DA /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = Info.plist; sourceTree = "<group>"; };
8E2B8B4A0B9B48D000F2D9E8 /* Plugin.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Plugin.h; path = ../../Audio/Plugin.h; sourceTree = SOURCE_ROOT; };
D2F7E65807B2D6F200F64583 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; };
/* End PBXFileReference section */
@ -95,7 +95,7 @@
08FB77AFFE84173DC02AAC07 /* Classes */ = {
isa = PBXGroup;
children = (
177FCF380B90C8F10011C3B5 /* Plugin.h */,
8E2B8B4A0B9B48D000F2D9E8 /* Plugin.h */,
17ADB2000B9793FF00257CA2 /* MusepackPlugin.h */,
17ADB2010B9793FF00257CA2 /* MusepackPlugin.m */,
170333090B8FB64500327265 /* MusepackDecoder.h */,

View File

@ -12,10 +12,8 @@
@interface MusepackDecoder : NSObject <CogDecoder>
{
FILE *inFd;
id<CogSource> source;
mpc_decoder decoder;
mpc_reader_file reader;
mpc_streaminfo info;
char buffer[MPC_FRAME_LENGTH*4];
int bufferAmount;
@ -26,6 +24,7 @@
}
- (BOOL)writeSamplesToBuffer:(uint16_t *)sample_buffer fromBuffer:(const MPC_SAMPLE_FORMAT *)p_buffer ofSize:(unsigned)p_size;
- (NSDictionary *)properties;
- (void)setSource:(id<CogSource>)s;
- (id<CogSource>)source;
@end

View File

@ -10,24 +10,75 @@
@implementation MusepackDecoder
- (BOOL)open:(NSURL *)url
mpc_int32_t ReadProc(void *data, void *ptr, mpc_int32_t size)
{
NSLog(@"Decoder opening...$@", url);
inFd = fopen([[url path] UTF8String], "rb");
if (inFd == 0)
return NO;
MusepackDecoder *decoder = (MusepackDecoder *) data;
mpc_reader_setup_file_reader(&reader , inFd);
return [[decoder source] read:ptr amount:size];
}
mpc_bool_t SeekProc(void *data, mpc_int32_t offset)
{
MusepackDecoder *decoder = (MusepackDecoder *) data;
return [[decoder source] seek:offset whence:SEEK_SET];
}
mpc_int32_t TellProc(void *data)
{
MusepackDecoder *decoder = (MusepackDecoder *) data;
return [[decoder source] tell];
}
mpc_int32_t GetSizeProc(void *data)
{
MusepackDecoder *decoder = (MusepackDecoder *) data;
if ([[decoder source] seekable]) {
long currentPos = [[decoder source] tell];
[[decoder source] seek:0 whence:SEEK_END];
long size = [[decoder source] tell];
[[decoder source] seek:currentPos whence:SEEK_SET];
return size;
}
else {
return 0;
}
}
mpc_bool_t CanSeekProc(void *data)
{
MusepackDecoder *decoder = (MusepackDecoder *) data;
return [[decoder source] seekable];
}
- (BOOL)open:(id<CogSource>)s
{
[self setSource: s];
mpc_reader reader = {
read: ReadProc,
seek: SeekProc,
tell: TellProc,
get_size: GetSizeProc,
canseek: CanSeekProc
};
mpc_streaminfo info;
mpc_streaminfo_init(&info);
if (mpc_streaminfo_read(&info, &reader.reader) != ERROR_CODE_OK)
if (mpc_streaminfo_read(&info, &reader) != ERROR_CODE_OK)
{
NSLog(@"Not a valid musepack file.");
return NO;
}
/* instantiate a decoder with our file reader */
mpc_decoder_setup(&decoder, &reader.reader);
mpc_decoder_setup(&decoder, &reader);
if (!mpc_decoder_initialize(&decoder, &info))
{
NSLog(@"Error initializing decoder.");
@ -41,6 +92,10 @@
length = ((double)mpc_streaminfo_get_length_samples(&info)*1000.0)/frequency;
NSLog(@"Length: %lf", length);
[self willChangeValueForKey:@"properties"];
[self didChangeValueForKey:@"properties"];
return YES;
}
@ -128,7 +183,7 @@
- (void)close
{
fclose(inFd);
[source close];
}
- (double)seekToTime:(double)milliseconds
@ -138,6 +193,23 @@
return milliseconds;
}
- (void)setSource:(id<CogSource>)s
{
[s retain];
[source release];
source = s;
}
- (id<CogSource>)source
{
return source;
}
- (BOOL)seekable
{
return [source seekable];
}
- (NSDictionary *)properties
{
return [NSDictionary dictionaryWithObjectsAndKeys:
@ -150,6 +222,8 @@
nil];
}
+ (NSArray *)fileTypes
{
return [NSArray arrayWithObject:@"mpc"];

View File

@ -11,13 +11,13 @@
@implementation MusepackPropertiesReader
- (NSDictionary *)propertiesForURL:(NSURL *)url
+ (NSDictionary *)propertiesForSource:(id<CogSource>)source
{
NSDictionary *properties;
MusepackDecoder *decoder;
decoder = [[MusepackDecoder alloc] init];
if (![decoder open:url])
if (![decoder open:source])
{
return nil;
}