Author |
Topic: wav files (Read 394 times) |
|
roy
New Member
member is offline


Posts: 44
|
 |
wav files
« Thread started on: Feb 28th, 2018, 12:24pm » |
|
Hi all
i've been trying to play wav sound files on Android. I can get them to play on the lap top using BBCSDL, but when copied over to Android they do not play.
Any one got any ideas. regards Roy
SND_ASYNC = 1 SND_FILENAME = &20000 REM wave$ = "\windows\media\tada.wav" wave$ = "wow.wav" SYS "PlaySound", wave$, 0, SND_FILENAME + SND_ASYNC
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
Re: wav files
« Reply #1 on: Feb 28th, 2018, 7:35pm » |
|
on Feb 28th, 2018, 12:24pm, roy wrote:| i've been trying to play wav sound files on Android. I can get them to play on the lap top using BBCSDL, but when copied over to Android they do not play. |
|
Is the code you listed what you have been trying on Android? It's Windows code (probably copied from the BB4W Help file) so of course can't possibly work! 
You will probably find code that you can adapt in 'xd2.bbc' (David Williams's 'Xmas Demo II') which plays a WAV file to accompany the graphics. See this thread.
Richard.
|
|
Logged
|
|
|
|
roy
New Member
member is offline


Posts: 44
|
 |
Re: wav files
« Reply #2 on: Mar 2nd, 2018, 11:39am » |
|
Hi Richard
Thanks for the link. When I downloaded it and tried to extract it. It said "Bad zip", so that's as far as I got. Any ideas would be welcome.
Would you let me have the BBC2APK app
Many thanks Roy
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
Re: wav files
« Reply #3 on: Mar 2nd, 2018, 12:53pm » |
|
on Mar 2nd, 2018, 11:39am, roy wrote:| When I downloaded it and tried to extract it. It said "Bad zip", so that's as far as I got. |
|
I've just checked the file: it's absolutely fine here (I've not tried unzipping it, as such, since that's not necessary in Windows if you just want to extract xd2.bbc). I can only suggest you try again; make sure the download hasn't aborted early, the file length should be exactly 8,735,157 bytes.
Quote:| Would you let me have the BBC2APK app |
|
Sorry, I've decided not to release it because (a) too few testers reported back and (b) those that did had terrible problems with it.
I am going to try to learn the lesson this time, and not be tempted in future to create something beyond my greatly diminished abilities.
Richard.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
Re: wav files
« Reply #4 on: Mar 2nd, 2018, 2:16pm » |
|
on Mar 2nd, 2018, 12:53pm, Richard Russell wrote:| I've just checked the file: it's absolutely fine here |
|
I realised that the routines are short enough to fit into a message here, so if you want to save yourself the trouble of extracting them from xd2.bbc here you go (this code has not yet been adapted to be 64-bit compatible):
Code: DEF FNLoadSound(path$) LOCAL A%, P%, R% DIM P% 7 : REM allocate from heap SYS "SDL_RWFromFile", path$, "rb" TO R% IF R% = 0 ERROR 114, "Couldn't open sound file: " + path$ SYS "SDL_LoadWAV_RW", R%, 1, AudioSpec{}, P%, P%+4 TO A% IF A% = FALSE ERROR 115, "Couldn't buffer sound: " + path$ SYS "memcmp", A%, AudioSpec{}, 9 TO R% IF R% ERROR 116, "Couldn't convert sound format: " + path$ = P% DEF PROCPlaySound(P%) LOCAL temp{} : DIM temp{} = AudioSpec{} IF @hwo% = FALSE SYS "SDL_OpenAudioDevice", FALSE, FALSE, AudioSpec{}, temp{}, 0, @memhdc% TO @hwo% IF @hwo% = FALSE ERROR 117, "Couldn't open audio device" SYS "SDL_ClearQueuedAudio", @hwo%, @memhdc% SYS "SDL_QueueAudio", @hwo%, !P%, P%!4, @memhdc% SYS "SDL_PauseAudioDevice", @hwo%, FALSE, @memhdc% ENDPROC Richard.
|
|
Logged
|
|
|
|
roy
New Member
member is offline


Posts: 44
|
 |
Re: wav files
« Reply #5 on: Mar 4th, 2018, 09:11am » |
|
Thanks very much Richard, for getting the listings.
It's a shame about the BBC2APK app, it would have been very useful.
When I was on the RFO Basic form 2 guys made APK app by combining the basic program with the basic interpreter. I don't know if that is food for thought.
Regards Roy
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
Re: wav files
« Reply #6 on: Mar 4th, 2018, 1:10pm » |
|
on Mar 4th, 2018, 09:11am, roy wrote:| It's a shame about the BBC2APK app, it would have been very useful. |
|
What I've said at the discussion group is that if I receive more (positive) reports from testers I will reconsider my decision. At the moment I've received so little feedback - and that has been mixed - it would be reckless to release it.
Perhaps I should not be surprised, but only a small proportion of those who enthusiastically asked to be allowed to test it have even acknowledged receipt of the download, let alone provided any feedback.
If you want me to release the utility, tell those people to get their fingers out!
Quote:| When I was on the RFO Basic form 2 guys made APK app by combining the basic program with the basic interpreter. I don't know if that is food for thought. |
|
In what sense? That is how all interpreted languages create their standalone executables, including BBC BASIC for Windows, LB Booster and BBC BASIC for Android!
My BBC2APK utility works! It takes a BBC BASIC program, plus resource files, libraries etc., and creates a fully standalone, signed APK. My decision not to release it is not because it doesn't work. 
Richard.
|
|
|
|
roy
New Member
member is offline


Posts: 44
|
 |
Re: wav files
« Reply #7 on: Mar 6th, 2018, 10:01am » |
|
Hi Richard
I would like to test the BBC2APK utility and report back to you with the results. I have 3 android devices, 2 tables and a phone.
I'm semiretired, so may have a bit more time then others.
To get back to playing wav files.
The listing will play only the first wav file, in this case the wow.wav, but then the others will not play. if I rem out the wow.stuff then the beep.wav plays, but not the others, and so on.
Any ideas.
Thanks Roy
Code: 10 on error if err=17 chain @lib$+"../examples/tools/touchide" else mode 3 : procCleanup : print report$; " At line " erl : wait 1000 100 150 dim Src{x%, y%, w%, h%}, Dst{x%, y%, w%, h%} 160 dim AudioSpec{freq%, _format%, channels&, silence&, samples{l&,h&}, size%, _callback%, userdata%} 170 AudioSpec.freq% = 44100 180 AudioSpec._format% = &8010 : rem AUDIO_S16LSB 190 AudioSpec.channels& = 2 200 21 220 print"Playing: wow.wav" 230 Music% = fnLoadSound(@dir$ + "sounds/wow.wav") 240 if Music% = 0 print "Error" : error 100, "Couldn't load music file" 250 procPlaySound(Music%) 260 wait 200 310 320 print"Playing: beep.wav" 330 Music% = fnLoadSound(@dir$ + "sounds/beep.wav") 340 if Music% = 0 print "Error" : error 100, "Couldn't load music file" 350 procPlaySound(Music%) 360 wait 200 410 420 print"Playing: click.wav" 430 Music% = fnLoadSound(@dir$ + "sounds/click.wav") 440 if Music% = 0 print "Error" : error 100, "Couldn't load music file" 450 procPlaySound(Music%) 460 wait 200 510 520 print"Playing: dogsOut.wav" 530 Music% = fnLoadSound(@dir$ + "sounds/dogsOut.wav") 540 if Music% = 0 print "Error" : error 100, "Couldn't load music file" 550 procPlaySound(Music%) 560 wait 400 570 580 procCleanup 590 print"End" 600 repeat wait 4 : until false 610 620 def procCleanup 630 if @hwo% then 640 sys "SDL_CloseAudioDevice", @hwo%, @memhdc% 650 sys "SDL_FreeWAV", !Music%, @memhdc% 660 endif 670 endproc 680 690 def fnLoadSound(path$) 700 local A%, P%, R% 710 dim P% 7 : rem allocate from heap 720 sys "SDL_RWFromFile", path$, "rb" to R% 730 if R% = 0 error 114, "Couldn't open sound file: " + path$ 740 sys "SDL_LoadWAV_RW", R%, 1, AudioSpec{}, P%, P%+4 to A% 750 if A% = false error 115, "Couldn't buffer sound: " + path$ 760 sys "memcmp", A%, AudioSpec{}, 9 to R% 770 if R% error 116, "Couldn't convert sound format: " + path$ 780 = P% 790 800 def procPlaySound(P%) 810 local temp{} : dim temp{} = AudioSpec{} 820 if @hwo% = false sys "SDL_OpenAudioDevice", false, false, AudioSpec{}, temp{}, 0, @memhdc% to @hwo% 830 if @hwo% = false error 117, "Couldn't open audio device" 840 sys "SDL_ClearQueuedAudio", @hwo%, @memhdc% 850 sys "SDL_QueueAudio", @hwo%, !P%, P%!4, @memhdc% 860 sys "SDL_PauseAudioDevice", @hwo%, false, @memhdc% 870 endproc
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
Re: wav files
« Reply #8 on: Mar 6th, 2018, 11:25am » |
|
on Mar 6th, 2018, 10:01am, roy wrote:| The listing will play only the first wav file, in this case the wow.wav, but then the others will not play. |
|
Are you trying to play them simultaneously or sequentially? Playing multiple sounds at once requires SDL_mixer, which I don't link with BBC BASIC. Playing them sequentially, however, ought to be as simple as omitting the SYS "SDL_ClearQueuedAudio" statement, but I've never needed to do that myself.
You're breaking new ground with BBCSDL so you can expect to have to study the SDL2 online documentation to figure out what you need to do, and write the code from scratch. It's not difficult (often easier than the Windows API) but requires care.
It will be very valuable indeed to have somebody other than me who is able to do that, because I worry that when I am no longer around - or able to provide assistance - all people will ever write in BBC BASIC is trivial code. 
Richard.
|
|
Logged
|
|
|
|
vbi
Guest
|
 |
Re: wav files
« Reply #9 on: Mar 6th, 2018, 5:34pm » |
|
Roy,
For sequential, I think all you need to do is add a line to free the current wave file before the next load/play operation.
This works for me (BBC SDL on Win7, with my specific wave files) -
Code: DIM AudioSpec{freq%, format%, channels&, silence&, samples{l&,h&}, size%, callback%, userdata%} AudioSpec.freq% = 44100 AudioSpec.format% = &8010 : REM AUDIO_S16LSB AudioSpec.channels& = 2 REM Load and Play Wave File No.1 Music% = FNLoadSound("c:\InOut\Test Card Music\23 - Going Places.wav") IF Music% = 0 ERROR 100, "Couldn't load music file" PROCPlaySound(Music%) WAIT 1000 : REM = 10 Second Excerpt REM Free Wave File No.1 SYS "SDL_FreeWAV", !Music%, @memhdc% REM Load and Play Wave File No.2 Music% = FNLoadSound("c:\InOut\Test Card Music\06 - Waltz in Jazztime.wav") IF Music% = 0 ERROR 100, "Couldn't load music file" PROCPlaySound(Music%) WAIT 1000 : REM = 10 Second Excerpt REM Cleanup properly when finished PROCCleanup END DEF FNLoadSound(path$) LOCAL A%, P%, R% DIM P% 7 : REM allocate from heap SYS "SDL_RWFromFile", path$, "rb" TO R% IF R% = 0 ERROR 114, "Couldn't open sound file: " + path$ SYS "SDL_LoadWAV_RW", R%, 1, AudioSpec{}, P%, P%+4 TO A% IF A% = FALSE ERROR 115, "Couldn't buffer sound: " + path$ SYS "memcmp", A%, AudioSpec{}, 9 TO R% IF R% ERROR 116, "Couldn't convert sound format: " + path$ = P% DEF PROCPlaySound(P%) LOCAL temp{} : DIM temp{} = AudioSpec{} IF @hwo% = FALSE SYS "SDL_OpenAudioDevice", FALSE, FALSE, AudioSpec{}, temp{}, 0, @memhdc% TO @hwo% IF @hwo% = FALSE ERROR 117, "Couldn't open audio device" SYS "SDL_ClearQueuedAudio", @hwo%, @memhdc% SYS "SDL_QueueAudio", @hwo%, !P%, P%!4, @memhdc% SYS "SDL_PauseAudioDevice", @hwo%, FALSE, @memhdc% ENDPROC DEF PROCCleanup IF @hwo% THEN SYS "SDL_CloseAudioDevice", @hwo%, @memhdc% SYS "SDL_FreeWAV", !Music%, @memhdc% ENDIF ENDPROC
|
|
Logged
|
|
|
|
roy
New Member
member is offline


Posts: 44
|
 |
Re: wav files
« Reply #10 on: Mar 6th, 2018, 7:34pm » |
|
Hi Richard
Thanks for the suggestion and I did find some SDL2 online documentation, so I'll have a look at that.
Omitting SYS "SDL_ClearQueuedAudio" didn't make any difference
Hi vbi
Thanks for the suggestion and I had tried that, but again it didn't make any difference.
It will play one wav fill many times, in my case the click each time a number is tapped, then when something happens and I try to play the wow.wav nothing appends.
Thanks for all help
Regards Roy
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
Re: wav files
« Reply #11 on: Mar 6th, 2018, 8:35pm » |
|
on Mar 6th, 2018, 7:34pm, roy wrote:| It will play one wav fill many times, in my case the click each time a number is tapped, then when something happens and I try to play the wow.wav nothing appends. |
|
I don't see why it should make a difference but try it this way (it's how the sound effects in Forces of Darkness are produced so I know it can work). I've omitted any error handling for simplicity:
Code: wow% = FNLoadSound(@dir$ + "sounds/wow.wav") beep% = FNLoadSound(@dir$ + "sounds/beep.wav") click% = FNLoadSound(@dir$ + "sounds/click.wav") dogsOut% = FNLoadSound(@dir$ + "sounds/dogsOut.wav") PROCPlaySound(wow%) WAIT 200 PROCPlaySound(dogsOut%) WAIT 400 If that still doesn't work one possible explanation might be that your WAV files are not all using the same format (sampling rate, bit depth, number of channels etc). If necessary re-encode them so they are all the same format.
Richard.
|
|
|
|
roy
New Member
member is offline


Posts: 44
|
 |
Re: wav files
« Reply #12 on: Mar 7th, 2018, 8:41pm » |
|
Hi Richard
That made no difference and I do not know how to re-encode them, so I tried some different wav files and manage to get three to play one after another , but when I added a forth the first one played OK and then the next two played slowed down and the last one played OK
I guess they do need re-encode.
Regards Roy
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
Re: wav files
« Reply #13 on: Mar 7th, 2018, 9:36pm » |
|
on Mar 7th, 2018, 8:41pm, roy wrote:| That made no difference and I do not know how to re-encode them. |
|
Google, as so often, is your friend. There are web sites that will do it for you. For example this one.
Richard.
|
|
Logged
|
|
|
|
vbi
Guest
|
 |
Re: wav files
« Reply #14 on: Mar 8th, 2018, 09:59am » |
|
Hello Roy,
I'm glad to see that you've made some progress. Re-encoding all your wav files to the same format may well make your life easier. However, it is possible to play files of differing format encoding and sample rates sequentially with a little modification to the code.
In case it is useful to you, or indeed others, here in an example based on Richards's original code that works for me -
Code: DIM AudioSpecRequired{freq%, format%, channels&, silence&, samples{l&,h&}, size%, callback%, userdata%} DIM AudioSpecObtained{} = AudioSpecRequired{} REM Define some default settings - should be overwritten when WAV file is loaded AudioSpecRequired.freq% = 44100 AudioSpecRequired.format% = &8010 : REM AUDIO_S16LSB AudioSpecRequired.channels& = 2 max% = 4 DIM WavFile$(max%-1) WavFile$(0) = "c:\InOut\Test Card Music\23 - Going Places.wav" WavFile$(1) = "c:\InOut\Test Wavs\a2002011001-e02-ulaw.wav" WavFile$(2) = "c:\InOut\Test Wavs\a2002011001-e02-16kHz.wav" WavFile$(3) = "c:\InOut\Test Wavs\11k16bitpcm.wav" w% = 0 REPEAT Music% = FNLoadSound(WavFile$(w%)) IF Music% = 0 ERROR 100, "Couldn't load music file" PROCPlaySound(Music%) PROCAudioInfo(WavFile$(w%)) WAIT 1000 : REM = 10 Second Excerpt PROCCleanup w%+=1 UNTIL FALSE OR w% = max% END DEF FNLoadSound(path$) LOCAL A%, P%, R% DIM P% 7 : REM allocate from heap SYS "SDL_RWFromFile", path$, "rb" TO R% IF R% = 0 ERROR 114, "Couldn't open sound file: " + path$ SYS "SDL_LoadWAV_RW", R%, 1, AudioSpecRequired{}, P%, P%+4 TO A% IF A% = FALSE ERROR 115, "Couldn't buffer sound: " + path$ SYS "memcmp", A%, AudioSpecRequired{}, 9 TO R% IF R% ERROR 116, "Couldn't convert sound format: " + path$ = P% DEF PROCPlaySound(P%) IF @hwo% = FALSE SYS "SDL_OpenAudioDevice", FALSE, FALSE, \ \ AudioSpecRequired{}, AudioSpecObtained{}, 0, @memhdc% TO @hwo% IF @hwo% = FALSE ERROR 117, "Couldn't open audio device" SYS "SDL_ClearQueuedAudio", @hwo%, @memhdc% SYS "SDL_QueueAudio", @hwo%, !P%, P%!4, @memhdc% SYS "SDL_PauseAudioDevice", @hwo%, FALSE, @memhdc% ENDPROC DEF PROCAudioInfo(now$) LOCAL p%, tmp%, fmt$ PRINT "Now Playing > "+now$ FOR p% = 0 TO 1 IF p% tmp% = AudioSpecObtained.format% ELSE tmp% = AudioSpecRequired.format% REM This is a not an exhaustive list! CASE (tmp% AND &FFFF) OF WHEN &0008 : fmt$ = "AUDIO_U8" WHEN &8008 : fmt$ = "AUDIO_S8" WHEN &0010 : fmt$ = "AUDIO_U16LSB" WHEN &8010 : fmt$ = "AUDIO_S16LSB" WHEN &1010 : fmt$ = "AUDIO_U16MSB" WHEN &9010 : fmt$ = "AUDIO_S16MSB" OTHERWISE fmt$ = "UNDEFINED" ENDCASE IF p% THEN PRINT "Obtained Audio Device Sample Freq = "+STR$(AudioSpecObtained.freq%) PRINT "Obtained Audio Device Format) = "+fmt$ ELSE PRINT "Required Audio File Sample Freq = "+STR$(AudioSpecRequired.freq%) PRINT "Required Audio File Format = "+fmt$ ENDIF NEXT p% ENDPROC DEF PROCCleanup IF @hwo% THEN SYS "SDL_CloseAudioDevice", @hwo%, @memhdc% SYS "SDL_FreeWAV", !Music%, @memhdc% @hwo% = FALSE ENDIF ENDPROC
(Note: All the original PROCs have been modified in some way in this example)
This will (via the addition of PROCAudioInfo) print the current audio spec sample rate and format to the screen as the files are played -
All but one of the test files came from here - http://www.music.helsinki.fi/tmt/opetus/uusmedia/esim/index-e.html and here - https://en.wikipedia.org/wiki/WAV
Again, this has been tested on Win7, as I'm nowhere near modern enough to have ever possessed an Android device!
I hope it may help someone.
|
| « Last Edit: Mar 8th, 2018, 10:03am by vbi » |
Logged
|
|
|
|
|