Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Programming Sound under Linux
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Multimedia
View previous topic :: View next topic  
Author Message
paulj
Guru
Guru


Joined: 30 Sep 2004
Posts: 513
Location: Wales, UK

PostPosted: Fri Feb 23, 2018 1:10 pm    Post subject: Programming Sound under Linux Reply with quote

I want to generate sounds with a program (as opposed to playing a sound file), but there is a surprising lack of up to date information about how to go about this process. Are any of you aware of decent, recent documentation or tutorials to enable programming of polyphonic sound, ideally in C/C++, but I'll take anything at the moment!

Many thanks!
Back to top
View user's profile Send private message
audiodef
Watchman
Watchman


Joined: 06 Jul 2005
Posts: 6639
Location: The soundosphere

PostPosted: Sat Feb 24, 2018 4:01 pm    Post subject: Reply with quote

I'm not aware of C/C++ sound programming, but if you are not insistent on using C, check out Supercollider and ChucK. You will need ChucK from the Gentoo Studio overlay (https://github.com/audiodef/gentoostudio) but the Portage ebuild of Supercollider looks ok to go. There's also PureData, which you can get from https://github.com/gentoo-audio/audio-overlay.

If you have a spare machine to play with, you can install Gentoo Studio on it, where these programs, along with lots of others, are ready out of the box.
_________________
decibel Linux: https://decibellinux.org
Github: https://github.com/Gentoo-Music-and-Audio-Technology
Facebook: https://www.facebook.com/decibellinux
Discord: https://discord.gg/73XV24dNPN
Back to top
View user's profile Send private message
paulj
Guru
Guru


Joined: 30 Sep 2004
Posts: 513
Location: Wales, UK

PostPosted: Sun Feb 25, 2018 2:32 pm    Post subject: Reply with quote

Thanks audiodef. I am aware of the gentoo studio, and have been promising to load it up on one of my machines for some time (I play saxophone, clarinet and guitar and wanted to explore it further).
Coming originally from a Commodore Amiga background, I was surprised to find that programming sound seems to be such a niche activity. I want to use C/C++ because the sound is simply an output, and not the be-all and end-all of the application - I want to experiment with shepard tones, as a precursor to experimenting with a new type of vario for model gliders. I don't want to learn another language in order to achieve this aim. There is a book I came across called "Linux Sound Programming" (https://www.apress.com/gb/book/9781484224953), but the preview pages seem to show that this spends lots of pages regurgitating things like pulseaudio configuration files and not on the core concepts. I am not encouraged to pay good money for it...
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10590
Location: Somewhere over Atlanta, Georgia

PostPosted: Sun Feb 25, 2018 4:12 pm    Post subject: Reply with quote

Some simple audio file formats (e.g., .wav) seem to be trivially easy to find on the Internet. For instance, here, here, and here. Is this not what you're looking for? And why create anything other than a simple format, so long as it's versatile enough to support multiple bit rates and channels? There are a myriad of encoders available to convert to whatever final format you want. Those structures are likewise easy to create in C/C++.

Similarly, for programmatic audio output, there seem to be some tutorials on the ALSA Project site.

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
audiodef
Watchman
Watchman


Joined: 06 Jul 2005
Posts: 6639
Location: The soundosphere

PostPosted: Sun Feb 25, 2018 5:59 pm    Post subject: Reply with quote

paulj, I have this giant tome of computer music written in the 90's that I have not even read yet, but I do know it's hard to find good books about the topic.

If you come across something about programming sounds in C/C++, would you let me know? I would find this interesting.
_________________
decibel Linux: https://decibellinux.org
Github: https://github.com/Gentoo-Music-and-Audio-Technology
Facebook: https://www.facebook.com/decibellinux
Discord: https://discord.gg/73XV24dNPN
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 6920

PostPosted: Sun Feb 25, 2018 6:10 pm    Post subject: Reply with quote

SDL seems to be able to cope with sound being generated and pushed to it in realtime, if that's what you meant to do. There's also OpenAL but I've heard it's downright painful to program for.
Back to top
View user's profile Send private message
paulj
Guru
Guru


Joined: 30 Sep 2004
Posts: 513
Location: Wales, UK

PostPosted: Sun Feb 25, 2018 6:32 pm    Post subject: Reply with quote

John R. Graham wrote:
Some simple audio file formats (e.g., .wav) seem to be trivially easy to find on the Internet. For instance, here, here, and here. Is this not what you're looking for? And why create anything other than a simple format, so long as it's versatile enough to support multiple bit rates and channels? There are a myriad of encoders available to convert to whatever final format you want. Those structures are likewise easy to create in C/C++.

Similarly, for programmatic audio output, there seem to be some tutorials on the ALSA Project site.

- John


What I want to do is this:

Code:
Generate a polyphonic tone, with three notes each one octave apart.
while true [
     Read the pressure from the barometric sensor
     calculate the new height
     calculate the pitch of the new tone
     generate the three notes based on this, adjusting the relative volumes to enhance the Shepard Tone effect
]


Ultimately this should occur in a microcontroller, or using something like a raspberry pi, but for the first stage, I wanted to create a test program on my desktop, with dummy input. I guess I could generate a selection of wav files and play those, but I should be able to generate the notes programmatically. The stuff on the ALSA site seems to be dreadfully out of date, and actually suggests you use the information provided for Jack. However, this also seems to be sparse in terms of information. I'll keep looking!


Last edited by paulj on Sun Feb 25, 2018 6:34 pm; edited 1 time in total
Back to top
View user's profile Send private message
paulj
Guru
Guru


Joined: 30 Sep 2004
Posts: 513
Location: Wales, UK

PostPosted: Sun Feb 25, 2018 6:33 pm    Post subject: Reply with quote

Ant P. wrote:
SDL seems to be able to cope with sound being generated and pushed to it in realtime, if that's what you meant to do. There's also OpenAL but I've heard it's downright painful to program for.


Thanks Ant P. - I'll look into this.
Back to top
View user's profile Send private message
Irre
Guru
Guru


Joined: 09 Nov 2013
Posts: 434
Location: Stockholm

PostPosted: Sun Feb 25, 2018 7:31 pm    Post subject: Reply with quote

Try to implement your music generating programs on a graphic card with billions of transistors! :)
Back to top
View user's profile Send private message
geki
Advocate
Advocate


Joined: 13 May 2004
Posts: 2387
Location: Germania

PostPosted: Sun Feb 25, 2018 8:29 pm    Post subject: Reply with quote

Since I may come back to my pacman 3d game written in university, to do some sound refactoring, I may reference these for me and others interested:

OpenAL looks good for 3D sound effects:
https://www.openal.org/documentation/OpenAL_Programmers_Guide.pdf
https://stackoverflow.com/questions/5469030/c-play-back-a-tone-generated-from-a-sinusoidal-wave

PortAudio:
https://app.assembla.com/spaces/portaudio/wiki
https://app.assembla.com/spaces/portaudio/git/source/master/test
https://app.assembla.com/spaces/portaudio/git/source/master/test/patest_sine8.c <-- sinusoidal wave


have fun! :o
_________________
hear hear
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Multimedia All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum