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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Notnasiul

Pages: [1]
1
Audio / Creating an oscillator
« on: August 08, 2011, 03:57:42 pm »
lol, ok, I'll try SFML 2.0, although compiling it is being a hell! (well, it did compile with Visual Studio express edition 2008, but now I'm getting lots of undefined references on my application... so still trying to link everything correctly!)

2
Audio / Creating an oscillator
« on: August 08, 2011, 01:54:08 pm »
Could anyone try this or was I punished for working with 1.6? :D

3
Audio / Pitch detection algorithms
« on: August 06, 2011, 07:50:12 pm »
Is SFML suitable for implementing pitch detection algorithms? I guess so, given that accessing sound buffers is relatively simple and fast.

At first I considered AMDF, as it seems easy to implement. Indeed, I already implemented it in Processing, but I switched to SFML looking for speed. I could consider FFT based algorithms, using the FFTW library to extract the Fourier Transform.

But I would like some advice from someone with a little bit of experience. Have you tried to detect pitch from a recorded human voice?

4
Audio / Creating an oscillator
« on: July 25, 2011, 02:09:52 pm »
Sorry, still with 1.6. I know you told me to switch to 2.0, but I did not manage to prepare it with cmake for codeblocks. That's in my todo list :(

5
Audio / Creating an oscillator
« on: July 25, 2011, 02:05:51 pm »
Ok, let's see...

Oscillator.h
Code: [Select]

#ifndef __OSCILLATOR__
#define __OSCILLATOR__

#include <SFML/Audio.hpp>
#include <iostream>
#include <math.h>

#define NSAMPLES 44100

class Oscillator
{
public :
    Oscillator (float frequency, float amplitude);
    void setTone(float frequency, float amplitude);

private :
    sf::SoundBuffer buffer;
    sf::Sound sound;

    sf::Int16 samples[NSAMPLES];
};
#endif


Oscillator.cpp
Code: [Select]

#include "Oscillator.h"

Oscillator::Oscillator(float frequency, float amplitude) {
    setTone( frequency, amplitude);
    sound.SetLoop(true);
    sound.Play();
}

void Oscillator::setTone(float frequency, float amplitude) {
    for (int i = 0; i < NSAMPLES; i++) {
        samples[i] = ( amplitude * sin(frequency * (2.0f * 3.1415f) * i / 44100));
    }
    buffer.LoadFromSamples(samples, NSAMPLES, 1, 44100);
    sound.SetBuffer(buffer);
}


main.cpp
Code: [Select]

#include <SFML/Audio.hpp>
#include "Oscillator.h"

int main() {
   Oscillator *o = new Oscillator(440, 10000);
   sf::Sleep(2.0f);
   o->setTone(880,10000); // but we still hear 440 after this...
   sf::Sleep(2.0f);
   return 0;
}


SetTone works the first time it's called, in the constructor. But samples won't change the second time it's called, after two seconds.

EDIT: I guess this is not the right way of doing this. I should have a look at soundstream...

6
Audio / Creating an oscillator
« on: July 25, 2011, 01:49:54 pm »
Right, and I guess that scale corresponds to the amplitude. It works.

Now, using Loop that sound will play forever, even in background (great!). And this is where I'm not sure whether I have to use a soundbuffer or a soundstream...

Say I created those samples at 440Hrz, but now I want to change their frequency to 880Hrz. If I update the samples vector, reload them in the soundbuffer and reasign this soundbuffer to the current sound, it will simply ignore me and keep playing the previous frequency. That's where I guess a soundstream will be handy: I just would feed it with new samples at 880.

I don't know, that may be a complete nonsense. The question would be: how would I change a sound's buffer samples while it's playing?

This post seems to be related: http://www.sfml-dev.org/forum/viewtopic.php?t=3929&postdays=0&postorder=asc&start=0, I'll read it ;)

7
Audio / Creating an oscillator
« on: July 25, 2011, 01:01:30 pm »
Has anyone done this? I'm starting with SFML, so I'm still pretty lost. I found this basic effect generator http://www.sfml-dev.org/forum/viewtopic.php?t=3449&highlight=soundman which is great for precise sound effects, but I need something that creates a continuous sound. That is, an oscillator.

I guess I have to fill a soundbuffer with the right samples (using a sine wave, knowing the target frequency and amplitude), feed it to a sound object and play it. But I must be doing something wrong... Just as a test I did this:

Code: [Select]

#include <SFML/Audio.hpp>
#include "math.h"

int main()
{
    int nSamples = 10000; // How many samples do I need for a cycle?
    sf::Int16 samples[nSamples];
    sf::SoundBuffer buffer;
    sf::Sound sound;
    //Fill samples with a pure A tone (440hrz)
    for (int i = 0; i < nSamples ; i++) {
        samples[i] = ( sin(440.0f * (2.0f * 3.1415f) * i / 44100));
    }
    bool ok = buffer.LoadFromSamples(samples, nSamples , 1, 44100);
    if (!ok) exit(-1);
    sound.SetBuffer(buffer);
    sound.Play();
    sf::Sleep(5.0f);
    return 0;
}


Nothing is heard when executed...

8
Audio / Increasing Sound::GetPlayingOffset() precision
« on: July 24, 2011, 12:36:51 am »
Um... I may consider adopting SFML 2 for this project. Thanks!

9
Audio / Increasing Sound::GetPlayingOffset() precision
« on: July 24, 2011, 12:11:42 am »
What a pity... Well, is SFML2 reliable enough for a relatively big project? :D I know I can download it from sourceforge but, when is it expected to be released?

10
Audio / Increasing Sound::GetPlayingOffset() precision
« on: July 23, 2011, 05:00:04 pm »
Hi! First post in these forums : ) First of all, congratulations for this great library.

I'm working with sound in a project that is closely related to a karaoke. Therefore, I need access to sound buffers. At some point,  sound/music is playing and I must get the raw values from the buffer from the exact playing offset.

It's easy by knowing its sample rate and the playing offset. However, sound.GetPlayingOffset() returns floats with just two decimals (e.g. 2.23) so the resolution is pretty low.

If I use Clock.GetElapsedTime() the precision is higher (e.g. 2.23154), which is more discriminative. Just see this example:

2.22 x 44100 -> 97902
2.23 x 44100 -> 98343

There are like 1000 samples lost in just 1/100 seconds. But it's even worse: many consecutive calls return the same playing offset, so I get the same sample even when time has obviously advanced (a few milliseconds, but it's not the same)

If I do something like this (just imagine that Sound is already playing):

Code: [Select]
std::cout << Clock.GetElapsedTime() << " " << Sound.GetPlayingOffset() << std::endl

see how Clock is much more precise than GetPlayingOffset in this few samples:

0.060948 0.06
0.0629533 0.06
0.0649569 0.06
0.0667986 0.06
0.0687719 0.06
0.0704301 0.07
0.072469 0.07
0.074509 0.07
0.0758784 0.07
0.0778292 0.07

I hope I managed to explain myself... Is it possible to increase GetPlayingOffset somehow?

Pages: [1]