BBC BASIC for Windows
Programming >> Sound, Music and Video >> API calls for Sound and Video
http://bb4w.conforums.com/index.cgi?board=multimedia&action=display&num=1224828282

API calls for Sound and Video
Post by GordonSweet on Oct 24th, 2008, 06:04am

In view of the number of Library files already kindly made available mostly by Richard, would it not be a good idea if someone could manage to create one to make it simpler, especially for beginners, be able to play MP3, WMA and Video files. Also to access the 128 sounds using the WINMM.DLL ?

Gordon

Re: API calls for Sound and Video
Post by admin on Oct 24th, 2008, 09:07am

Quote:
would it not be a good idea if someone could manage to create one to make it simpler, especially for beginners, be able to play MP3, WMA and Video files. Also to access the 128 sounds using the WINMM.DLL ?

Sounds like a good idea. Are you volunteering to do the work? It would need the appropriate code to be extracted from (e.g.) http://www.bbcbasic.co.uk/bbcwin/examples/player.html and packaged up into a library format.

Incidentally, playing MP3, WMA files and so on is dependent on suitable codecs being installed. The library you propose isn't magically going to make an ancient Windows 98 PC able to play them!

Richard.
Re: API calls for Sound and Video
Post by GordonSweet on Oct 24th, 2008, 10:50am

I will have a try Richard soon.

Gordon
Re: API calls for Sound and Video
Post by Malcolm on Oct 24th, 2008, 3:49pm

Thanks, Richard, for reminding me that the Example file existed. I was getting frustrated with commercial players always trying to give visual displays and looks up things on the web that I did not want. Now I see I can optimize my own little player.

Malcolm.


Re: API calls for Sound and Video
Post by GordonSweet on Oct 30th, 2008, 1:33pm

If any did not see the posting in the Yahoo BBC4W Group I have produced a MEDIA.LIB to play any of the Video and Sound files as with Player.bas, it also allows access to the 128 Instrumental sounds provided by Windows WINMM.DLL. The latter can be useful when creating games etc. It can ne found among the groups Library Files as Media.zip, and includes a Demo program Test Media Lib.bas. It does not have the same functions of STOP and PAUSE of Player.bas just a quick way of finding and playing medial files

Both files can also be downloaded from among http://www.sigord.co.uk/BBC/BBCBASIC.htm
among the Progaids.

Gordon

Re: API calls for Sound and Video
Post by admin on Oct 30th, 2008, 2:53pm

Quote:
It can be found among the groups Library Files

It's useful to remind people here that, although Conforums does not have an upload capability, the Yahoo group's Files area is available for that purpose. Since most Conforums members will, I assume, also subscribe to the Yahoo group, uploading files there and linking to them from here is a practical solution (even though care must be taken to get the link right!).
Re: API calls for Sound and Video
Post by Malcolm on Nov 15th, 2008, 5:57pm

A CD, MP3, WMA ans WAV player.

http://tech.groups.yahoo.com/group/bb4w/files/Sound-Music/AudioPlayerPlus.zip

Code, executable and notes.
Re: API calls for Sound and Video
Post by Malcolm on Dec 5th, 2008, 3:01pm

The audio Player based on the MCI API's has been updated and is here:

http://tech.groups.yahoo.com/group/bb4w/files/Sound-Music/AudioPlayer/AudioPlayer2_6a.zip

Version française

http://tech.groups.yahoo.com/group/bb4w/files/Sound-Music/AudioPlayer/AudioLecteur2_6a.zip
Re: API calls for Sound and Video
Post by Trevor on Apr 16th, 2009, 11:47am

Question

Can you access Sound or Music through the PC ports and record and store as a file in BBC4 formatt.

The reason for this is sampling sounds and musical instruments to experiment with blending sounds. smiley
Re: API calls for Sound and Video
Post by admin on Apr 16th, 2009, 9:59pm

Quote:
Can you access Sound or Music through the PC ports and record and store as a file

Certainly. See this Wiki article for how to input real-time audio:

http://bb4w.wikispaces.com/Inputting+real-time+audio

and various programs here for how to output the audio to a file:

http://groups.yahoo.com/group/bb4w/files/Sound-Music/

Richard.
Re: API calls for Sound and Video
Post by 19Grumpah42 on Oct 14th, 2009, 07:44am

[quote author=Guest-Malcolm link=board=multimedia&num=1224828282&start=7#0 date=1228492883]
>The audio Player based on the MCI API's has been >updated and is here:

>http://tech.groups.yahoo.com/group/bb4w/files/Sound-Music/AudioPlayer/AudioPlayer2_6a.zip

I am enormously impressed with this, over 1000 lines of terse code. I am a beginner! Could you briefly but cogently tell me *why* all this coding is an improvement over something like....

DIM wav_4% size%-1
OSCLI "LOAD """+wave$+""" "+STR$~wav_4%
beats_address%(4)=wav_4%

SYS "PlaySoundA", beats_address%(J%), 0, 5

(which would play a *.WAV file loaded into memory)

Is it about 'high precision timers', or what?
I realise that your program is multi-purpose whereas the above is single purpose. I would like to know what I am missing out on by not using all that MS boilerplate.
--Grahame
Re: API calls for Sound and Video
Post by Michael Hutton on Oct 14th, 2009, 11:19am

Grahame,

1. Versatility - The matter really rests with the ability to play lots of different types of files. "PlaySound" only plays wav files which are uncompressed PCM format files, and can be very large. The Audioplayer also plays mpg and others (as stated previously by Richard, it depends if the codecs are also installed). How many of your music files are in wav format? Not very many I would guess.

2. Memory Space - your specific method of DIM'ing the space for the file from memory will 'waste' that memory. You could use the "GlobalAlloc" to get windows to save a bit of memory for you. Alternatively playing the wav from file is better in this case, look at "Playing WAV files" in the manual.

3. A lot more reasons others could elucidate better than I.

Michael




Re: API calls for Sound and Video
Post by admin on Oct 14th, 2009, 1:29pm

Quote:
your specific method of DIM'ing the space for the file from memory will 'waste' that memory

That particular shortcoming can be overcome by using:

Code:
DIM wav_4% LOCAL size%-1 

(inside a procedure or function) without having to resort to calling the Windows API.

Richard.
Re: API calls for Sound and Video
Post by Malcolm on Oct 14th, 2009, 1:46pm

Quote:
I am enormously impressed with this, over 1000 lines of terse code. I am a beginner! Could you briefly but cogently tell me *why* all this coding is an improvement over something like....


Terse? This program has a host of REM's explaining what each section is doing. The Procedure names and variables are also quite descriptive (in my view).
As Michael says it was versatile: plays lots of audio types and CD tracks and controls them (stop/start/pause etc). Lets you know what is playing, how far into the track. Lets you open a window to select files. Lets you drag and drop music files. Lets you double click onto a file to play it. You can control the volume and so on and on. None of which your snippet would do. If you understand not one line of code then just listing the REM's would tell you quite a lot about what it is doing. Is it an improvement? Well it depends on what you want to do. The program does nearly everything I wanted it to do, but if you just want to play a known wave file at the standard volume from within your program, with no user interface, then there are 990 lines too many.

It's kind of like saying is a Mercedes an improvement over a pair of roller skates? Sometimes, Yes!


Regards, Malcolm
Re: API calls for Sound and Video
Post by 19Grumpah42 on Oct 15th, 2009, 04:16am

Thanks for the hearty replies everybody! It certainly is a very rich programme, Malcolm. I'm sure that Richard would agree that I was yet again blind-sided by all the MS stuff!!

My immediate wish was just to load a series of pseudo-system sounds - my own audio recordings, typically less than 100kBy each - which are invoked programmatically in connection with an A/V metronome for my granddaughters to use alongside their playing and singing. I don't really care much about memory usage (I think) since I have 3 GBy on mine and my son has 4 GBy on his.

--Grahame
Re: API calls for Sound and Video
Post by admin on Oct 15th, 2009, 08:22am

Quote:
My immediate wish was just to load a series of pseudo-system sounds - my own audio recordings, typically less than 100kBy each

Definitely sounds like a case where the simplest code is the best:

Code:
wave$ = @dir$+"yourfile.wav"
SYS "PlaySound", wave$, 0, &20001 

The Help documentation is arguably misleading because it implies that if you want to play a sound multiple times you should load it into memory first. That's unnecessary for short files like yours because Windows will do a good job of 'cacheing' the files in memory anyway.

So simply repeating the above code should be absolutely fine.

Richard.
Re: API calls for Sound and Video
Post by Malcolm on Feb 28th, 2010, 03:12am

The AudioPlayerPlus has been updated and partially recoded.

This removes the methods that Richard was objecting to but is still based on MCI, which is an old set of Windows API's which will one day go away. In this application it uses the file extensions to select which device to open so no extension, no play.

This version has the slider for track positioning suggested by Simon only it has been made quite a bit more slick. (and bigger target)
I also made the counter up/down switch act like Windows Media player, i.e. just click on the numbers to change mode.

Otherwise it does what it always did, be a small window that you can drop audio files onto and play them. If you drop a folder onto the window it will extract any audio files in there. (Can't go into nested folders though).

You can even drop files or a folder onto a link or shortcut which will fire up the player and play the contents. The files can be played randomly, repeatedly and stuff like that. No playlists because I don't like them. And sometimes things that you initially don't "get" are great bits of music.

Plays whatever you have codecs for. MP3, Wav, WMA, MIDI and mpegs, cda, and CDs either as a whole or by track and so on.
This is still a fresh version so there are likely to be some minor issues.

http://tech.groups.yahoo.com/group/bb4w/files/%22Temp%20Folder%22/AudioPlayerPlus3_02.exe


Re: API calls for Sound and Video
Post by Malcolm on Feb 28th, 2010, 3:37pm



OK So I wrote:
Quote:
No playlists because I don't like them.


If anyone wants these I could probably be persuaded to recognize M3U. If there is any interest then let me know.
Re: API calls for Sound and Video
Post by 81RED on Feb 28th, 2010, 3:41pm

In case I have not said so already: Fantastic job Malcolm. cheesy

If I'm allowed just one more minor suggestion, then it would be to change the sensitivity of the mouse scrollwheel volume adjustment - as it is right now, it takes nine full "twiddles" of my finger to go from one extreme to the other, and that feels a bit too much like an exercise if you ask me.
Re: API calls for Sound and Video
Post by Malcolm on Feb 28th, 2010, 4:07pm

Scroll sensitivity....

Yes, I suppose I agree with that comment. I am sure we can crank that up.

Thanks for your comments and I am glad you like it.
Re: API calls for Sound and Video
Post by Malcolm on Mar 1st, 2010, 12:45am

Here is your wish Simon, the scroll is 7 times faster so you should be done within two twiddles at most.

It appeared that M3U style Playlists were popular and they are a simple format so it was pretty easy to allow them to be dropped or opened just like individual music files. Don't forget that relative paths can be used in Playlists stored with the music files. I have to freeze this project very soon.

http://tech.groups.yahoo.com/group/bb4w/files/%22Temp%20Folder%22/AudioPlayerPlus3_03.exe
Re: API calls for Sound and Video
Post by 81RED on Mar 2nd, 2010, 11:04am

Thank you Malcolm, that made a world of difference.
Re: API calls for Sound and Video
Post by Malcolm on Mar 13th, 2010, 2:56pm

AudioPlayerPlus now in Sound_Music folder with source.

This appears to be stable.

http://tech.groups.yahoo.com/group/bb4w/files/Sound-Music/AudioPlayer/AudioPlayerPlus3_1.exe

I have added PLS playlists to the MU3, otherwise it is the same old basic small footprint music player. For those who don't want large applications constantly trolling the internet trying to sell you music, here is a solution.