0
0

I tried to use RecordToDisk example for a start. Then changed some parts.

This all works fine for sounds loaded from another WAV, as I tested.
But I need to load from DLS. Select subSound from it. And then save the sound to a file.

I just tried to do this. No success.
Then I just replaced the sound with an external wav sound. With no code change. All works.

When I say no success, I mean File is created, it contains some data.
But when I try to play it, I see that it’s much shorter than the original sound, and sounds absolutely different from the original sound.

[code:204fbujr]- (void)writeDataFromChannelWithArgs:(NSArray *)args
{
FMOD_RESULT result = FMOD_OK;
FMOD::Sound * theSound = (FMOD::Sound *)[[args objectAtIndex:1] pointerValue];
NSString * path = [args objectAtIndex:2];
const char * cPath = [path cStringUsingEncoding:NSASCIIStringEncoding];
remove(cPath);
FILE * file;
file = fopen(cPath, "wb");
if (!file)
{
NSLog(@"ERROR : could not open %@ for writing.\n", path);
return;
}
[self writeWavHeaderToFile:file andSound:theSound andLength:0];

int channels, bits;
float rate;
FMOD_SOUND_FORMAT format;
unsigned int length;

theSound->getFormat(0, &format, &channels, &bits);
theSound->getDefaults(&rate, 0, 0, 0);
theSound->getLength(&length,  FMOD_TIMEUNIT_PCM);
NSLog(@"%d", length);
const unsigned int  CHUNKSIZE   = 4096;

unsigned int        bytesRead   = 0; 
void           *ptr1        = NULL; 
void           *ptr2        = NULL; 

unsigned int    len1        = 0; 
unsigned int    len2        = 0; 


bytesRead = 0; 
do 
{ 

    result = theSound->lock(bytesRead, CHUNKSIZE, &ptr1, &ptr2, &len1, &len2); 
    ERRCHECK(result); 

    if (ptr1 && len1) { 
        bytesRead += fwrite(ptr1, 1, len1, file); 
    } 
    if (ptr2 && len2) { 
        bytesRead += fwrite(ptr2, 1, len2, file); 
    } 
    result = theSound->unlock(ptr1, ptr2, len1, len2); 
    ERRCHECK(result); 


    //NSLog(@"Written %d bytes of %d to wav file", bytesRead, length); 
} 
while (result == FMOD_OK && bytesRead < length); 


if (file) 
{ 
    fclose(file); 
    file = NULL; 
    NSLog(@"Sound object written to file"); 
} 

}[/code:204fbujr][/code]

  • You must to post comments
Showing 0 results
Your Answer

Please first to submit.