ga_Sound* ga_sound_create_sample_source(ga_SampleSource* in_sampleSrc) { ga_Sound* ret = 0; ga_Format format; gc_int32 dataSize; gc_int32 totalSamples; ga_SampleSource* sampleSrc = in_sampleSrc; gc_int32 sampleSize; ga_sample_source_format(sampleSrc, &format); sampleSize = ga_format_sampleSize(&format); ga_sample_source_tell(sampleSrc, &totalSamples); if(totalSamples > 0) { /* Known total samples*/ char* data; ga_Memory* memory; dataSize = sampleSize * totalSamples; data = gcX_ops->allocFunc(dataSize); ga_sample_source_read(sampleSrc, data, totalSamples, 0, 0); memory = gaX_memory_create(data, dataSize, 0); if(memory) { ret = ga_sound_create(memory, &format); if(!ret) ga_memory_release(memory); } else gcX_ops->freeFunc(data); } else { /* Unknown total samples */ gc_int32 BUFFER_SAMPLES = format.sampleRate * 2; char* data = 0; ga_Memory* memory; totalSamples = 0; while(!ga_sample_source_end(sampleSrc)) { gc_int32 numSamplesRead; data = gcX_ops->reallocFunc(data, (totalSamples + BUFFER_SAMPLES) * sampleSize); numSamplesRead = ga_sample_source_read(sampleSrc, data + (totalSamples * sampleSize), BUFFER_SAMPLES, 0, 0); if(numSamplesRead < BUFFER_SAMPLES) { data = gcX_ops->reallocFunc(data, (totalSamples + numSamplesRead) * sampleSize); } totalSamples += numSamplesRead; } memory = gaX_memory_create(data, totalSamples * sampleSize, 0); if(memory) { ret = ga_sound_create(memory, &format); if(!ret) ga_memory_release(memory); } else gcX_ops->freeFunc(data); } return ret; }
void gauX_data_source_memory_close(void* in_context) { gau_DataSourceMemoryContext* ctx = (gau_DataSourceMemoryContext*)in_context; ga_memory_release(ctx->memory); gc_mutex_destroy(ctx->memMutex); }
static void gaX_sound_destroy(ga_Sound* in_sound) { ga_memory_release(in_sound->memory); gcX_ops->freeFunc(in_sound); }