Home |
Function USBAudioPlay |
Function USBAudioPlayUSBAudioPlay submits data for playback to an Audio function: int USBAudioPlay(int AudioID, const void * Data, UINT Len, DWORD Flags); ParametersAudioIDAudio ID value previously returned by function USBAudioGetInfo. DataPointer to a block of audio data to play. LenNumber of bytes pointed to by parameter Data. Flags0 or optional flag USB_PLAY_VERBOSE. If USB_PLAY_VERBOSE is specified, minor warnings (if any) are display through function RTUDiagMessage. Severe warnings and errors are always displayed. return valueNumber of currently queued transactions or a negative error code in case of an error. USBAudioPlay may only be called on audio functions with Direction RTUOutput (see USBAudioGetInfo). The data pointed to by parameter Data must have the correct format and frequency for the audio function (see USBAudioGetInfo and USBAudioGetFrequency). If this is not the last data segment of a sound data stream, Len should specify a length which evaluates to an integral number of milliseconds. For example, if the audio function has 2 channels and requires 2 bytes per channel at a frequency of 24000 Hertz. Len should be a multiple of 24000 * 2 * 2 / 1000 = 96. For a frequency of 22050 Hertz, the data should be a multiple of 22050 * 2 * 2 / 1000 * 20 = 1764. In total, at most 1 second worth of data can be submitted for playback. The maximum amount of data accepted by a single call of USBAudioPlay depends on RTUSBAudioConfig.MaxIOsPlay. For example, if RTUSBAudioConfig.MaxIOsPlay is 2 (default), at most 1000 / 2 = 500 milliseconds of data are accepted. If RTUSBAudioConfig.MaxIOsPlay is 5, 1000 / 5 = 200 milliseconds can be played with a single call. USBAudioPlay does not wait until the audio device has consumed all of the submitted data. Rather, it uses RTUStartIO to start a transaction and then returns to the application immediately. The application may not access or deallocate the submitted data buffer before USBAudioWaitDone has been called and returns the buffer address submitted with this call. USBAudioPlay returns the number of transactions currently pending. Once it returns RTUSBAudioConfig.MaxIOsPlay, the application must call USBAudioWaitDone to let at least one transaction complete before USBAudioPlay may be called again. At the end of the audio data stream, the application should call USBAudioWaitDone for each still pending transaction.
|