www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Help playing sounds using arsd.simpleaudio

reply Murilo <murilomiranda92 hotmail.com> writes:
Can anyone just please show me how to play a background 
sound(like those in games) using arsd.simpleaudio? I'd like 
something simple with a code snippet please.
Sep 27 2019
next sibling parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Saturday, 28 September 2019 at 03:21:38 UTC, Murilo wrote:
 Can anyone just please show me how to play a background 
 sound(like those in games) using arsd.simpleaudio? I'd like 
 something simple with a code snippet please.
it is really minimal be warned but at the beginning of main() set it up with auto audio = new AudioPcmOutThread(); audio.start(); scope(exit) { audio.stop(); audio.join(); } and then when you want it to make sounds, call its functions like audio.beep(); or audio.playOgg("my-file.ogg"); you can convert things like wav and mp3 into the ogg format with various tools of the internet. that's about all it does.
Sep 28 2019
next sibling parent Murilo <murilomiranda92 hotmail.com> writes:
On Saturday, 28 September 2019 at 14:03:53 UTC, Adam D. Ruppe 
wrote:
 On Saturday, 28 September 2019 at 03:21:38 UTC, Murilo wrote:
 Can anyone just please show me how to play a background 
 sound(like those in games) using arsd.simpleaudio? I'd like 
 something simple with a code snippet please.
it is really minimal be warned but at the beginning of main() set it up with auto audio = new AudioPcmOutThread(); audio.start(); scope(exit) { audio.stop(); audio.join(); } and then when you want it to make sounds, call its functions like audio.beep(); or audio.playOgg("my-file.ogg"); you can convert things like wav and mp3 into the ogg format with various tools of the internet. that's about all it does.
Thank you sooo much. Now it works. That is pretty much what I was looking for.
Sep 28 2019
prev sibling next sibling parent reply Murilo <murilomiranda92 hotmail.com> writes:
On Saturday, 28 September 2019 at 14:03:53 UTC, Adam D. Ruppe 
wrote:
 On Saturday, 28 September 2019 at 03:21:38 UTC, Murilo wrote:
 Can anyone just please show me how to play a background 
 sound(like those in games) using arsd.simpleaudio? I'd like 
 something simple with a code snippet please.
it is really minimal be warned but at the beginning of main() set it up with auto audio = new AudioPcmOutThread(); audio.start(); scope(exit) { audio.stop(); audio.join(); } and then when you want it to make sounds, call its functions like audio.beep(); or audio.playOgg("my-file.ogg"); you can convert things like wav and mp3 into the ogg format with various tools of the internet. that's about all it does.
Thanks. Now, I would like to know if I could just use it like this instead: import arsd.simpleaudio; void main() { AudioPcmOutThread audio = new AudioPcmOutThread; audio.start; audio.playOgg("shock.ogg"); audio.join; audio.stop; }
Sep 28 2019
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Sunday, 29 September 2019 at 04:37:43 UTC, Murilo wrote:
 Thanks. Now, I would like to know if I could just use it like 
 this instead:
What happens if an exception is thrown in the middle of your function? It shouldn't really matter (at least not with the newer versions) since it will automatically exit the audio thread when the main thread exits, but still there's definitely no benefit to writing it without the scope guard.
Sep 29 2019
parent Murilo <murilomiranda92 hotmail.com> writes:
On Sunday, 29 September 2019 at 13:24:40 UTC, Adam D. Ruppe wrote:
 On Sunday, 29 September 2019 at 04:37:43 UTC, Murilo wrote:
 Thanks. Now, I would like to know if I could just use it like 
 this instead:
What happens if an exception is thrown in the middle of your function? It shouldn't really matter (at least not with the newer versions) since it will automatically exit the audio thread when the main thread exits, but still there's definitely no benefit to writing it without the scope guard.
I'm very minimalistic, I hate unnecessary complexity, I believe that simple is better than complex so I always try to use the least syntax and lines of code when I'm making a program. That is why I don't like the scope guard. Could I simply add the lines `audio.stop(); audio.join();` to the very end of main()?
Sep 29 2019
prev sibling next sibling parent reply Murilo <murilomiranda92 hotmail.com> writes:
On Saturday, 28 September 2019 at 14:03:53 UTC, Adam D. Ruppe 
wrote:
 On Saturday, 28 September 2019 at 03:21:38 UTC, Murilo wrote:
 Can anyone just please show me how to play a background 
 sound(like those in games) using arsd.simpleaudio? I'd like 
 something simple with a code snippet please.
it is really minimal be warned but at the beginning of main() set it up with auto audio = new AudioPcmOutThread(); audio.start(); scope(exit) { audio.stop(); audio.join(); } and then when you want it to make sounds, call its functions like audio.beep(); or audio.playOgg("my-file.ogg"); you can convert things like wav and mp3 into the ogg format with various tools of the internet. that's about all it does.
Are you sure it is like this: audio.stop(); audio.join(); and not like this: audio.join(); audio.stop(); ?
Sep 29 2019
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Sunday, 29 September 2019 at 20:51:40 UTC, Murilo wrote:
 Are you sure it is like this:
join waits for it to finish before returning. You need to stop before joining otherwise join may never return.
Sep 29 2019
parent reply Murilo <murilomiranda92 hotmail.com> writes:
On Sunday, 29 September 2019 at 20:57:09 UTC, Adam D. Ruppe wrote:
 On Sunday, 29 September 2019 at 20:51:40 UTC, Murilo wrote:
 Are you sure it is like this:
join waits for it to finish before returning. You need to stop before joining otherwise join may never return.
Alright, thanks. So let me see if I get this straight, .stop() will stop the thread and then .join() will return. But what exactly does .join() return?
Sep 29 2019
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Sunday, 29 September 2019 at 21:06:02 UTC, Murilo wrote:
 .stop() will stop the thread
More specifically, stop tells the audio output to stop. It finishes what it is doing and then exits. At this point, the thread terminates. join() waits for the thread to finish terminating (which it won't do if you don't tell it to stop *first*) and then cleans it up. join will return any exception/error it happened to throw while ending.
Sep 29 2019
parent reply Murilo <murilomiranda92 hotmail.com> writes:
On Sunday, 29 September 2019 at 22:52:02 UTC, Adam D. Ruppe wrote:
 On Sunday, 29 September 2019 at 21:06:02 UTC, Murilo wrote:
 .stop() will stop the thread
More specifically, stop tells the audio output to stop. It finishes what it is doing and then exits. At this point, the thread terminates. join() waits for the thread to finish terminating (which it won't do if you don't tell it to stop *first*) and then cleans it up. join will return any exception/error it happened to throw while ending.
ahh, okay, thanks. Now, one last question, if stop() actually makes the output, not the thread, stop, then start() makes the output, not the thread, begin?
Sep 29 2019
parent Adam D. Ruppe <destructionator gmail.com> writes:
On Sunday, 29 September 2019 at 23:48:35 UTC, Murilo wrote:
 Now, one last question, if stop() actually makes the output, 
 not the thread, stop, then start() makes the output, not the 
 thread, begin?
It does both. start is from the base class Thread, it starts it which immediately opens the audio device and can feed stuff when it is necessary.
Sep 29 2019
prev sibling parent reply Murilo <murilomiranda92 hotmail.com> writes:
 but at the beginning of main() set it up with


 	auto audio = new AudioPcmOutThread();
 	audio.start();
 	scope(exit) {
 		audio.stop();
 		audio.join();
 	}
Thanks Adam. That worked on Windows, but now that I have switched to Linux Mint it is throwing this: arsd.simpleaudio.AlsaException arsd/simpleaudio.d(1170): params init: Operation not permitted ---------------- ??:? arsd.simpleaudio.snd_pcm_t* arsd.simpleaudio.openAlsaPcm(arsd.simpleaudio.snd_pcm_stream_t) [0x55eab05a0f4a] ??:? ref arsd.simpleaudio.AudioOutput arsd.simpleaudio.AudioOutput.__ctor(int) [0x55eab059f7ec] ??:? void arsd.simpleaudio.AudioPcmOutThread.run() [0x55eab059f23d] ??:? void core.thread.Thread.run() [0x55eab05c10d1] ??:? thread_entryPoint [0x55eab05d809b] ??:? [0x7fb40e4ff6da] What should I do?
Oct 18 2019
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Saturday, 19 October 2019 at 01:48:57 UTC, Murilo wrote:
 init: Operation not permitted
Your system probably uses PulseAudio which I don't like, so I don't support it in my code. It *might* work to run `pasuspender -- ./your_program_here` but I don't know. I can check more tomorrow.
Oct 18 2019
parent reply Murilo <murilomiranda92 hotmail.com> writes:
On Saturday, 19 October 2019 at 02:10:54 UTC, Adam D. Ruppe wrote:
 On Saturday, 19 October 2019 at 01:48:57 UTC, Murilo wrote:
 init: Operation not permitted
Your system probably uses PulseAudio which I don't like, so I don't support it in my code. It *might* work to run `pasuspender -- ./your_program_here` but I don't know. I can check more tomorrow.
That unfortunately didn't work. I would be very grateful if you could find out a way around it and tell me.
Oct 18 2019
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
try it now with the new version of simpleaudio.d from git
Oct 19 2019
next sibling parent Murilo <murilomiranda92 hotmail.com> writes:
On Saturday, 19 October 2019 at 13:08:49 UTC, Adam D. Ruppe wrote:
 try it now with the new version of simpleaudio.d from git
Ahhhhhh, now it works! Thank you so much man. I really appreciate the work you do with your library, I have been using it for everything, I'm now training a neural network using your library.
Oct 19 2019
prev sibling parent reply Murilo <murilomiranda92 hotmail.com> writes:
On Saturday, 19 October 2019 at 13:08:49 UTC, Adam D. Ruppe wrote:
 try it now with the new version of simpleaudio.d from git
Hi Adam, sorry to bother you, but I'm having a problem with simpleaudio.d. This problem was happening on Windows too. When I play a sound the program never ends, the terminal continues to run the program and I have to end it manually. Any ideas what could be causing this? I am using it just as you had instructed.
Oct 26 2019
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Saturday, 26 October 2019 at 19:48:33 UTC, Murilo wrote:
 I play a sound the program never ends, the terminal continues 
 to run the program and I have to end it manually. Any ideas 
 what could be causing this? I am using it just as you had 
 instructed.
That happens if you don't call .stop() and .join() in order at the right time. Did you use the scope(exit) like I said?
Oct 30 2019
next sibling parent Murilo <murilomiranda92 hotmail.com> writes:
On Wednesday, 30 October 2019 at 19:11:00 UTC, Adam D. Ruppe 
wrote:
 On Saturday, 26 October 2019 at 19:48:33 UTC, Murilo wrote:
 I play a sound the program never ends, the terminal continues 
 to run the program and I have to end it manually. Any ideas 
 what could be causing this? I am using it just as you had 
 instructed.
That happens if you don't call .stop() and .join() in order at the right time. Did you use the scope(exit) like I said?
Thanks for the help. I did use the scope. Here is my code: AudioPcmOutThread audio = new AudioPcmOutThread(); audio.start(); scope (exit) { audio.stop(); audio.join(); } audio.playOgg("bell.ogg"); The problem persists.
Oct 31 2019
prev sibling parent johnsmith101 <johnsmith908412 gmail.com> writes:
On Wednesday, 30 October 2019 at 19:11:00 UTC, Adam D. Ruppe 
wrote:
 On Saturday, 26 October 2019 at 19:48:33 UTC, Murilo wrote:
 I play a sound the program never ends, the terminal continues 
 to run the program and I have to end it manually. Any ideas 
 what could be causing this? I am using it just as you had 
 instructed.
That happens if you don't call .stop() and .join() in order at the right time. Did you use the scope(exit) like I said?
hello, Thank you so much for help, it helped me alot Thanks and regards.:)
Nov 01 2019
prev sibling parent reply JN <666total wp.pl> writes:
On Saturday, 28 September 2019 at 03:21:38 UTC, Murilo wrote:
 Can anyone just please show me how to play a background 
 sound(like those in games) using arsd.simpleaudio? I'd like 
 something simple with a code snippet please.
I recommend SoLoud - bindings are available here http://code.dlang.org/packages/bindbc-soloud . It's more powerful than simpleaudio, supports multiple formats, 3D audio, etc.
Sep 29 2019
next sibling parent Adam D. Ruppe <destructionator gmail.com> writes:
On Sunday, 29 September 2019 at 09:25:59 UTC, JN wrote:
 It's more powerful than simpleaudio
heh. not hard to be better than my method list: http://dpldocs.info/experimental-docs/arsd.simpleaudio.AudioPcmOutThread.html#members beep boop blip noise playOgg it is meant to be something more like an Atari 2600 than a modern movie theater :)
Sep 29 2019
prev sibling parent Murilo <murilomiranda92 hotmail.com> writes:
On Sunday, 29 September 2019 at 09:25:59 UTC, JN wrote:
 On Saturday, 28 September 2019 at 03:21:38 UTC, Murilo wrote:
 Can anyone just please show me how to play a background 
 sound(like those in games) using arsd.simpleaudio? I'd like 
 something simple with a code snippet please.
I recommend SoLoud - bindings are available here http://code.dlang.org/packages/bindbc-soloud . It's more powerful than simpleaudio, supports multiple formats, 3D audio, etc.
Thanks.
Sep 29 2019