Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: question on SoundBuffer samples  (Read 2131 times)

0 Members and 1 Guest are viewing this topic.

theo Richard

  • Newbie
  • *
  • Posts: 8
    • View Profile
question on SoundBuffer samples
« on: June 17, 2015, 10:38:07 pm »
Hi ! I'am discovering the SoundBuffer while currently working on a pretty basic project :

I load a "A4.wav" containing the A4 key sound (La, 440hz) in a SoundBuffer called La

I then load a second Soundbuffer called Do with the sample, count, and rate of La, but I divide the rate by 1.68176432 to have give it the C sound (Do, 261.6hz)

I then play the Do sound and it plays the note well but the duration of the sound is longer than the La sound.

I think thats because by dividing the rate, fewer bytes are being played each second which lowers the frequence of the sound and increase its duration.

440 (A4 - La) / 1.68176432 = 261.6 (C - Do)

So I tried dividing the count value of the Do sound by 1.68176432 too, and it actually worked since the SoundBuffer.duration is now equals to the La's SoundBuffer.duration. But the Sound doesnt play anymore and I dont really understand why... :(

I then tried to play around with the samples of the Do's buffer too maybe shorten its length accordingly to the new found count value. but I couldnt really understand how to really do that  :-\

So I'd like to know if someone had any idea why the Sound doesnt play anymore, thanks in advance  :)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10821
    • View Profile
    • development blog
    • Email
Re: question on SoundBuffer samples
« Reply #1 on: June 17, 2015, 10:44:55 pm »
You might want to read up on sample rates with (PC) hardware. The sample rate is not something you change if you want things to be played differently.

If you just want to play around with simple sine waves, you'd be best off to generate your own buffers on the fly, that way you can pick whatever frequency you'd want.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

theo Richard

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: question on SoundBuffer samples
« Reply #2 on: June 17, 2015, 11:04:30 pm »
Oh I didnt thought I was so wrong  ;D

So basically I have to modify my La samples and change the count value accordingly ?

could you indicate me a documentation page or something about how I should go about that ? Im pretty clueless right now and I didnt found anything about modifying the samples in the sfml tutorials.

If you can't or don't want to bother, no problem and thanks anyway you have already been of great help  ;)
« Last Edit: June 17, 2015, 11:06:07 pm by theo Richard »

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 878
    • View Profile
Re: question on SoundBuffer samples
« Reply #3 on: June 17, 2015, 11:08:00 pm »
The number of samples per time should stay constant. You have to modify the actual values of the samples.

Last year I've done an example implementation of a method to write simple tunes into SFML's SoundBuffer.

You can find the code on GitHub. Note that this is outdated, but it should give you an idea on how to create sine, triangle, sawtooth, and rectangle waves (which are all popular waveforms used, e.g. for chiptune sounds).

theo Richard

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: question on SoundBuffer samples
« Reply #4 on: June 17, 2015, 11:14:13 pm »
Thanks a lot man thats perfect  ;)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10821
    • View Profile
    • development blog
    • Email
Re: question on SoundBuffer samples
« Reply #5 on: June 17, 2015, 11:24:18 pm »
A similar thing can be found in my last Ludum Dare game.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/