Just some shots in the dark.
USB stick startup times are random. Some are usable in immediately in human time and some are really slow.
The IOCTL_RESTART gives very thorough reset and if it can't find USB stuick it powers off the USB. So calling IOCTL_RESTART for VODEV('U') when your software wants to play from USB could be a solution.
if (ioctl(VODEV('U'), IOCTL_RESTART, NULL) == S_OK) { // Now it should work
} else { //Not working. side effect: USB perip is shut down
I don't know how badly everything breaks if the stick is unplugged during play. Probably needs some code to check that.
VS1010D USB Host Driver and MP3 play
-
- User
- Posts: 4
- Joined: Thu 2021-09-23 14:24
Re: VS1010D USB Host Driver and MP3 play
Hi Hannu,
Thanks for your reply. I tried:
And
Neither of them worked unfortunately. It just returns S_ERROR each time.
I have been able to get everything going by playing a short silent sound whenever I detect a USB connection. This seems to get the USB to mount in time to read its contents.
Thanks for your reply. I tried:
Code: Select all
if (ioctl(VODEV('U'), IOCTL_RESTART, NULL) == S_OK) { // working
}
Code: Select all
while (ioctl(VODEV('U'), IOCTL_RESTART, NULL) != S_OK) { // loop until it works
}
I have been able to get everything going by playing a short silent sound whenever I detect a USB connection. This seems to get the USB to mount in time to read its contents.
Re: VS1010D USB Host Driver and MP3 play
Something to try first:
ioctl(stdaudioout, IOCTL_RESTART, NULL)
In the beginning of your program. This is cheap. A call to ROM function.
The second thing the previous didn't work is to try that usb fix patch from:
viewtopic.php?p=14620#p14620
This cost some memory.
If this fixes the problem, then this is same problem which breaks on play r:hello.mp3 from USB serial console.
If the patch fixes your problem, you can write one sample long .wav file play it before usb host and everything should work. Restarting stdaudioout breaks USB configuration on VS1010d and first DAC output restarts stdaudio out or decode output. I don't remember exact detail.
ioctl(stdaudioout, IOCTL_RESTART, NULL)
In the beginning of your program. This is cheap. A call to ROM function.
The second thing the previous didn't work is to try that usb fix patch from:
viewtopic.php?p=14620#p14620
This cost some memory.
If this fixes the problem, then this is same problem which breaks on play r:hello.mp3 from USB serial console.
If the patch fixes your problem, you can write one sample long .wav file play it before usb host and everything should work. Restarting stdaudioout breaks USB configuration on VS1010d and first DAC output restarts stdaudio out or decode output. I don't remember exact detail.
Re: VS1010D USB Host Driver and MP3 play
The exact detail is that 1010D rom's InitAudio sets the initial sample rate by writing fixed values to some internal registers that control the clocks. These are difficult to verify pre-silicon so it's generally safer to write "known safe" values rather than do elaborate setting and resetting of individual bits - if you set them all, then you cannot have missed any. Unfortunately the ROM constant value written to one of the registers that control clock enables also switches off the USB clock (60.000), which has a rather zerodimensional effect on the operation of the chip if the core happens to be running from the USB clock.Hannu wrote: ↑Tue 2022-10-18 13:12 If this fixes the problem, then this is same problem which breaks on play r:hello.mp3 from USB serial console.
If the patch fixes your problem, you can write one sample long .wav file play it before usb host and everything should work. Restarting stdaudioout breaks USB configuration on VS1010d and first DAC output restarts stdaudio out or decode output. I don't remember exact detail.
Sorry about that.
Running InitAudio also sets audioInited=1, which prevents it from being run again, so if it's called before switching to USB clock, the chip generally works perfectly. My favorite way is to start user code from S:CONFIG.TXT (S: being something other than a USB stick) and add play r:hello.mp3 to the beginning of s:config.txt so that the audio is inited before loading anything. I also like the sound of my own voice so hearing it is not an issue for me.
The usb fix patch circumvents the issue by swithing the core to 1X clock before calling InitAudio, and then switches the clock back.
Hope this helps! Good luck!
-Panu
Info: Line In and Line Out, VS1000 User interface, Overlay howto, Latest VSIDE, MCU Howto, Youtube
Panu-Kristian Poiksalo
Panu-Kristian Poiksalo
-
- User
- Posts: 2
- Joined: Fri 2023-01-13 17:10
Re: VS1010D USB Host Driver and MP3 play
Hi Panu!
Question for you, is it possible on the VS1010 chip to play multiple mp3 files back to back. Currently we are playing one mp3 file and then waiting a predetermined about of time and then playing the second file, which leads to large gaps in between the two audio files. Can the chip indicate when one file is done playing and automatically play the next one?
We are using VS1010 chip with STM32 microcontroller on a custom build PCBA.
- Thanks, Lexi
Question for you, is it possible on the VS1010 chip to play multiple mp3 files back to back. Currently we are playing one mp3 file and then waiting a predetermined about of time and then playing the second file, which leads to large gaps in between the two audio files. Can the chip indicate when one file is done playing and automatically play the next one?
We are using VS1010 chip with STM32 microcontroller on a custom build PCBA.
- Thanks, Lexi
Re: VS1010D USB Host Driver and MP3 play
Hi,
The romplayer doesn't really have end marker. except it returns to VS1010> prompt so you would need to write your own player which would give that info. The time of the end of audio is when PlayerPlayFiles() function return.
If your SD-card has media in music directory, try to run play d:music/*mp3
The romplayer doesn't really have end marker. except it returns to VS1010> prompt so you would need to write your own player which would give that info. The time of the end of audio is when PlayerPlayFiles() function return.
If your SD-card has media in music directory, try to run play d:music/*mp3
-
- User
- Posts: 2
- Joined: Fri 2023-01-13 17:10
Re: VS1010D USB Host Driver and MP3 play
Hey Hannu,
We are trying to get multiple audio files to play back to back with out gapping. I posted here before and said that the VS1010 prompt come up after an audio file is done playing, that was great suggesting. I was able to read in the VS1010 and play the next audio when the previous file was done. The issue is there is still a decide gap in-between audio file for out application. Is there anyway to achieve this?
We have noticed that when we "brick" our board (pulling the power plug while programming) that all audio we have on out SD card will play in a loop and then gapping between files when this happens is almost seamless. Is there any way to replicate this with the desired audio file.
Any feedback out be greatly appreciated!
We are using VS1010 chip with STM32 microcontroller on a custom build PCBA.
-Thanks, Lexi
We are trying to get multiple audio files to play back to back with out gapping. I posted here before and said that the VS1010 prompt come up after an audio file is done playing, that was great suggesting. I was able to read in the VS1010 and play the next audio when the previous file was done. The issue is there is still a decide gap in-between audio file for out application. Is there anyway to achieve this?
We have noticed that when we "brick" our board (pulling the power plug while programming) that all audio we have on out SD card will play in a loop and then gapping between files when this happens is almost seamless. Is there any way to replicate this with the desired audio file.
Any feedback out be greatly appreciated!
We are using VS1010 chip with STM32 microcontroller on a custom build PCBA.
-Thanks, Lexi
Re: VS1010D USB Host Driver and MP3 play
Hi,
By the nature how mp3 works, gaples or noiseless change between files is impossible. (*
I created a small test signal 15 sec of 750 Hz sine. It starts from 0 and goes up and ends when next sample would be 0. So very nice looping property. Next I exported it as mp3. My test signal got low amplitude garbage to the start. That's why it is longer.
Next I used mp3 stream codec property and copy pasted it after itself. And the timing went worse. This is how Audacity does the decoding, and the same things happens probably with VSDSP audio codecs.
But. There is always a but.
Those two files are copies of original and wav files play after each other nicely and I didn't notice when file was changed. If using wav file is an option, use it.
Another option would be using cache and ogg file format. However after that you'll have very limited VS1010 environment where many rules are much diffent. I believe you don't want your development be that much interesting.
And having a partial write through USB disk is way to disaster. I don't even want to guess what has happened and how broken the file system has been.
(* Give some engineer enough time and resources, and you get on some level working and mostly failing solution just to prove something isn't impossible, but problematic and almost usable.
By the nature how mp3 works, gaples or noiseless change between files is impossible. (*
I created a small test signal 15 sec of 750 Hz sine. It starts from 0 and goes up and ends when next sample would be 0. So very nice looping property. Next I exported it as mp3. My test signal got low amplitude garbage to the start. That's why it is longer.
Next I used mp3 stream codec property and copy pasted it after itself. And the timing went worse. This is how Audacity does the decoding, and the same things happens probably with VSDSP audio codecs.
But. There is always a but.
Code: Select all
This will have noise.
VS1010>play s:test/sine*
sine_0k750_-8dB.mp3
sine_0k750_-8dB-2.mp3
This is just 30 sec of beep
VS1010>play s:test/s*wav
sine_0k750_-8dB.wav
sine_0k750_-8dB-2.wav
Another option would be using cache and ogg file format. However after that you'll have very limited VS1010 environment where many rules are much diffent. I believe you don't want your development be that much interesting.
And having a partial write through USB disk is way to disaster. I don't even want to guess what has happened and how broken the file system has been.
(* Give some engineer enough time and resources, and you get on some level working and mostly failing solution just to prove something isn't impossible, but problematic and almost usable.