Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 21:31 28 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Sounds for me game

Author Message
RCMAN
Newbie

Joined: 31/10/2020
Location: Canada
Posts: 29
Posted: 03:11am 30 Jan 2021
Copy link to clipboard 
Print this post

Hi

I'm putting sounds in my game but I find when playing .wav files it can slow down the CPU and cannot seem to play multiple sounds for my ship shooting and enemiess exploding around me.

Am I doing something wrong? It there an easier way to play multiple sounds at the same time?

Thanks
RC
Edited 2021-01-30 13:12 by RCMAN
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1082
Posted: 03:31am 30 Jan 2021
Copy link to clipboard 
Print this post

PLAY MODSAMPLE is very useful for this.
Visit Vegipete's *Mite Library for cool programs.
 
RetroJoe

Senior Member

Joined: 06/08/2020
Location: Canada
Posts: 290
Posted: 11:55am 30 Jan 2021
Copy link to clipboard 
Print this post

First off, you are not doing anything "wrong" - the CMM2 can only play one WAV (or MP3 or FLAC) file at a time.

Using PLAY MODSAMPLE is the only way I know of to play multiple PCM samples simultaneously. I would not characterize it as "easy", though, because you first need to create the MOD file with the samples you want to use in your game with a "MOD tracker" application, which is a nontrivial undertaking. If you have never heard of MOD files before, join the club :) MOD files originated on the Amiga and spawned a thriving "MOD scene" in the late 20th century. The file format is quite clever - it is a compound document containing multiple PCM samples, plus the "tracker" sequence data - think of that sequence part as an embedded MIDI file. The CMM2 can play an entire MOD file (i.e. a song), and/or the individual samples within the file - it is the latter capability you can leverage to play game sounds.

Two other techniques:

1) The PLAY WAV command has an optional "interrupt" parameter, that can call a subroutine when the WAV file has finished playing. You can use this capability to tell your main game loop (i.e. with global "semaphore" variables) when it's safe to play a new WAV file. Not the greatest technique, but should work if you have a small number of short sounds.

2) The PLAY SOUND command has no such threading limitation, and Mauro Xavier has built a "sound engine" that emulates 8-bit era sound chips using the CMM2's analog primitives of sine/square waves and white noise. Also falls into the "not easy" category, but if reading Mauro's code doesn't make your brain explode, this technique might work for you :)
Edited 2021-01-30 21:58 by RetroJoe
Enjoy Every Sandwich / Joe P.
 
RCMAN
Newbie

Joined: 31/10/2020
Location: Canada
Posts: 29
Posted: 04:59pm 30 Jan 2021
Copy link to clipboard 
Print this post

Thanks for the information, I am an old Amiga guy so I am familiar with mods.

I'll see if I can get this to work.

Thanks
RC
 
RCMAN
Newbie

Joined: 31/10/2020
Location: Canada
Posts: 29
Posted: 11:18pm 30 Jan 2021
Copy link to clipboard 
Print this post

One more question. How can I convert wav files to mod files?

Thanks
RC
 
hitsware2

Guru

Joined: 03/08/2019
Location: United States
Posts: 705
Posted: 11:24pm 30 Jan 2021
Copy link to clipboard 
Print this post

  RCMAN said  One more question. How can I convert wav files to mod files?

Thanks
RC

YES ! .....
Or , like on the Amiga , plot the waveshapes , and play them !
( Depending on the sounds you want , the SOUND and TONE
functions are much simpler )
Edited 2021-01-31 09:26 by hitsware2
my site
 
RCMAN
Newbie

Joined: 31/10/2020
Location: Canada
Posts: 29
Posted: 11:25pm 30 Jan 2021
Copy link to clipboard 
Print this post

  hitsware2 said  
  RCMAN said  One more question. How can I convert wav files to mod files?

Thanks
RC

YES ! .....
Or , like on the Amiga , plot the waveshapes , and play them !



My Amiga if very rusty. How would I do that?

RC
 
hitsware2

Guru

Joined: 03/08/2019
Location: United States
Posts: 705
Posted: 11:28pm 30 Jan 2021
Copy link to clipboard 
Print this post

I don't remember how .... But do remember doing it .
Maybe find an Amiga Basic manual ?
my site
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1082
Posted: 12:01am 31 Jan 2021
Copy link to clipboard 
Print this post

If you are on Windows, Audacity is good for manipulating audio samples and OpenMPT is good for assembling samples into a MOD file.
Visit Vegipete's *Mite Library for cool programs.
 
yock1960
Senior Member

Joined: 18/08/2020
Location: United States
Posts: 167
Posted: 05:42pm 31 Jan 2021
Copy link to clipboard 
Print this post

  vegipete said  If you are on Windows, Audacity is good for manipulating audio samples and OpenMPT is good for assembling samples into a MOD file.


Could you expound a bit on this vegipete? I installed OpenMPT 1.29 and see nothing for .mod files. There are some old plugins that I found, but they don't seem compatible (Win10). I suspect the sound in my current project/remake is going to be very choppy/clipped, once I start adding more features.

Steve
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1082
Posted: 06:55am 04 Feb 2021
Copy link to clipboard 
Print this post

Yes, OpenMPT is a bit strange to use.

First off, create your desired WAV files using Audacity.
You can record anything playing through the computer's speaker.

My procedure, once the sound is recorded, is:

1) convert to mono: (menu) Tracks --> Mix --> Mix Stereo Down to Mono

2) set consistent volume: Ctrl-A to select all, then Effect --> Amplify and set a target volume, or Effect --> Normalize

3) adjust the playback frequency. 44 or even 22 kHz seems unnecessarily high to me and just uses too much space and processor speed. I'm happy with 8000 Hz, you might prefer something else. Tracks --> Resample... and enter a value. Note this for later. (It may also be helpful to change the Project Rate (Hz) to match - drop down list bottom left corner of screen.)

4) Save the sound as a WAV file: File --> Export --> Export as WAV (defaults should be fine.)
Repeat for other sounds.

Now it's time to play with OpenMPT.
Start OpenMPT. (I've got version 1.29.03.00)
Start a new ... whatever it's called:  File --> New --> MOD
The new module opens, and the 'General' tab is selected.
Switch to the 'Samples' tab and load your wave files:



Select a wave file to load it. This will get loaded as sample 1.
Change to sample 2, load the next one. Repeat as required. (If you don't change the sample number, each one you load will replace the previous one.)
Also, there are a bunch of samples included with OpenMPT. You can find them in the MIDI Library and GM.DLS folders on the left side of the screen. Drag individual sounds to a _blank_ sample to include them.
Take note of which WAV is put in which sample number - you'll need this later.

You can listen to each sample quite easily. Select the sample number to hear, either from the sample number box, or with a click on the sample name on the left. The three rows of letter keys act as 'piano' keys. 'A' and ']' are close to 8000 Hz. 'N' is near 22 kHz. (Press 'Esc' to stop sounds that loop.)

Normally, the samples in a MOD file are instrument sounds - notes - and the music is defined by the patterns. For the CMM2, the pattern can be left blank and individual sounds can be played with the PLAY MODSAMPLE command.

You can save you work as a usable MOD file now: File --> Save As ... and give it a name.

Move the MOD file to the SD card in your CMM2 and try out those sounds!
The command is given in the manual:
PLAY MODSAMPLE sampleno, channelno [,volume][,samplerate]
The particular sample to play is given by the sample number, which you noted earlier.
Four simultaneous sounds should be possible, one on each of the channels 1 to 4. The sample rate should be the same as used in the original WAV although you can mess with this to change the pitch higher or lower if desired. If you don't specify the sample rate, it will default to 16000.

Hopefully the above helps with getting neat sound effect into you programs!
Visit Vegipete's *Mite Library for cool programs.
 
yock1960
Senior Member

Joined: 18/08/2020
Location: United States
Posts: 167
Posted: 10:28pm 04 Feb 2021
Copy link to clipboard 
Print this post

vegipete...you are the man! Works beautifully and much tidier than a bunch of individual files!

Thanks!

Steve
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024