PCM audio streaming error
Posted: Wed Apr 05, 2023 8:51 pm
I've been trying to get another video demo put together, but the audio (long a solved problem) has been a stumbling block this time around. I don't know whether this is due to an error in the emulator or if it's actually a problem with VERA. I think what's happening is that the PCM goes silent while new data is being written to the FIFO buffer. This wasn't the case in r41 or earlier versions.
Here's what I'm doing. I've got my audio at 16 bit 12970 Hz (audio rate of $22). I have the audio chopped up into 1/10 of a second chunks (2594 bytes) interlaced in a big file with the video image data (5kb per frame, also at 10 frames per second). The file is read sequentially using MACPTR. First 2594 bytes of audio data is stored in VRAM at $10000, then 5kb of video data is stored at $01000 or $03800, whichever isn't currently being displayed. The audio data gets pushed from VRAM to the PCM audio data in a very quick subroutine.
To start, the first clip of audio is loaded, and the first frame of video. Then with the audio rate set at 0, the first audio clip is pushed to the PCM FIFO, and the second audio clip and second frame of video loaded. Then I turn on the screen showing the first frame of video, set the audio rate to $22, and turn on interrupts. My Interrupt routine scans the ISR looking for bit 3 (AFLOW) to be one. If not, then it just goes to the default IRQ, but if it's a 1 the next audio clip is pushed to the FIFO, and a flag is set telling the main program to switch the video frame and load the next audio clip and video frame before going to the default IRQ.
All of that loading should take place in less than 1/10 of a second, I estimate about 75/1000 of a second. This leaves plenty of time remaining in the audio clip, so the audio should be seamless. Instead I'm getting "chatter" as the PCM goes silent between clips, and doesn't seem to play 1/10 of a second for each clip anyway. I took some recordings of what's happening in Audacity and saved some images: Anyhow, this is new behavior for the PCM. Is it an emulator error, or does the PCM audio go silent when streaming on the real hardware too? Because you can't push a whole lot of audio in just 4 kb between silences.
Here's what I'm doing. I've got my audio at 16 bit 12970 Hz (audio rate of $22). I have the audio chopped up into 1/10 of a second chunks (2594 bytes) interlaced in a big file with the video image data (5kb per frame, also at 10 frames per second). The file is read sequentially using MACPTR. First 2594 bytes of audio data is stored in VRAM at $10000, then 5kb of video data is stored at $01000 or $03800, whichever isn't currently being displayed. The audio data gets pushed from VRAM to the PCM audio data in a very quick subroutine.
To start, the first clip of audio is loaded, and the first frame of video. Then with the audio rate set at 0, the first audio clip is pushed to the PCM FIFO, and the second audio clip and second frame of video loaded. Then I turn on the screen showing the first frame of video, set the audio rate to $22, and turn on interrupts. My Interrupt routine scans the ISR looking for bit 3 (AFLOW) to be one. If not, then it just goes to the default IRQ, but if it's a 1 the next audio clip is pushed to the FIFO, and a flag is set telling the main program to switch the video frame and load the next audio clip and video frame before going to the default IRQ.
All of that loading should take place in less than 1/10 of a second, I estimate about 75/1000 of a second. This leaves plenty of time remaining in the audio clip, so the audio should be seamless. Instead I'm getting "chatter" as the PCM goes silent between clips, and doesn't seem to play 1/10 of a second for each clip anyway. I took some recordings of what's happening in Audacity and saved some images: Anyhow, this is new behavior for the PCM. Is it an emulator error, or does the PCM audio go silent when streaming on the real hardware too? Because you can't push a whole lot of audio in just 4 kb between silences.