I recall an older post raising issue with the documentation for the Sample_Upload function; I have since found no clarification. Is this intentional?
“This function uploads new sound data from memory to a preallocated/existing sample and does conversion based on the specified source mode.”
Well, of course the conversion is based on the source; but it is necessarily also based on the destination. Conversion = change. Here is my question–it is a simple one and requires an even simpler answer:
After executing FSOUND_Sample_Upload, the data format of the destination sample is what?
(a) the same format as the source;
(b) whatever format is specified in the 3rd parameter of the Sample_Upload function;
(c) the format of the “preallocated/existing” sample (i.e., the destination).
I suppose this can be answered only by the developer(s), but the answer will help me understand why my audio data is always corrupt after uploading from Sample A to Sample B.
- stdev asked 12 years ago
…Which makes the following problem even more peculiar. I am uploading a sample of format X to a preallocated sample of format X, and still I cannot duplicate the original data. You will recognize that what I’m trying to do–as a test of the Sample_Upload function–is to TRANSFER data from one sample to another.
Does someone see why the following process does NOT work? For brevity sake, trust me that the following code is sound (there are no errors or crashes), but there must be something wrong with MY application of the function (or with my understanding of the function’s true operation).
[b:1gu82j5k]hStream[/b:1gu82j5k] << I open a sound file in stream mode.
[b:1gu82j5k]hSample[/b:1gu82j5k] << a pointer to the stream sample.
[b:1gu82j5k]srcFormat [/b:1gu82j5k]<< the correct format for this audio data [derived using FSOUND_Sample_GetMode(hSample)]
[b:1gu82j5k]lenBytes [/b:1gu82j5k]<< the correct byte length for this media [derived using FSOUND_Stream_GetLength(hStream)
From here I can play or display the audio data, without problem. The following VB code, however, produces a copy of the original wav file with the same size, header (because I write it so), and duration. However, the audio data are “messed up” (I haven’t identified in what manner), as confirmed by the visual display and playback.
Do While bytePos < lenBytes
' set media byte position (and hence fetch a new sample) ret = SeekByte(bytePos) ' number of samples in the buffer sampBuf = FSOUND_Sample_GetLength(hSample) ' corresponding number of bytes byteBuf = sampBuf * blockAlign ' ignore any null data when we reach the end of the media IF bytePos + byteBuf > lenBytes Then byteBuf = lenBytes - bytePos ret = FSOUND_Sample_Lock(hSample, 0, byteBuf, ptr1A, ptr2A, len1A, len2A) hSampleOut = FSOUND_Sample_Alloc(FSOUND_FREE, sampBuf, srcFormat, srcFrequency, 255, 128, 255) ret = FSOUND_Sample_Upload(hSampleOut, hSample, srcFormat) ret = FSOUND_Sample_Lock(hSampleOut, 0, byteBuf, ptr1B, ptr2B, len1B, len2B) ReDim pcmData(0 To len1B - 1) As Byte Call CopyMemory(pcmData(0), ByVal ptr1B, ByVal len1B) ' the data are written to disc Put FileNumber, , pcmData ret = FSOUND_Sample_Unlock(hSampleOut, ptr1B, ptr2B, len1B, len2B) ret = FSOUND_Sample_Unlock(hSample, ptr1A, ptr2A, len1A, len2A) ret = FSOUND_Sample_Free(hSampleOut) ' derive next media position bytePos = bytePos + byteBuf DoEvents
You will notice the regular use of [b:1gu82j5k]srcFormat [/b:1gu82j5k]throughout the process. Why, then, is the original audio format lost?
I appreciate your assistance,
[quote:1o2stl41]why are you passing an FSOUND_SAMPLE handle to the parameter in FSOUND_Sample_Upload that is supposed to be taking raw PCM data?
ret = FSOUND_Sample_Upload(hSampleOut, ptr1A, m_sampleMode)
…crashes VB, whereas the original code does not.
But I forced myself to accept that you were on to something, and then realized the precise VB solution. The correct code is:
ret = FSOUND_Sample_Upload(hSampleOut, ByVal ptr1A, srcFormat)
As for the repeated use of [b:1o2stl41]srcFormat[/b:1o2stl41], it is correct in this example, because the exercise was to copy the audio data (i.e., duplicate the original format).
Thank you, Brett. I hope this working example will be useful for others.
Please login first to submit.