Menu

Tree [72de52] master /
 History

HTTPS access


File Date Author Commit
 include 2018-06-30 Gyorgy Kovesdi Gyorgy Kovesdi [5d410b] Generic ThirdOrderFunction
 src 2024-03-13 Gyorgy Kovesdi Gyorgy Kovesdi [72de52] Memory handling is fixed
 .gitignore 2017-09-15 György Kövesdi György Kövesdi [b424e4] First revision is added
 LICENSE 2017-09-15 György Kövesdi György Kövesdi [c01234] Initial commit
 Makefile 2017-09-15 György Kövesdi György Kövesdi [b424e4] First revision is added
 README.md 2017-10-17 György Kövesdi György Kövesdi [d961e8] Updated README
 project-info 2017-09-19 György Kövesdi György Kövesdi [255b98] Added FFT

Read Me

soundelf

An easy to use object oriented library for playing and recording sound.

Currently it uses 32-bit floating point data type and based on ALSA. However,
it is easy to implement other backends (see the classes SND::Device,
SND::DeviceHandler, and the ALSA implementation for more information).

It is based on the following libraries:

The development packages are also necessary for ALSA and FFTW.

HOW TO USE IT

1) Include this header file:

#include <device-interface.h>

2) Instantiate the device handler singleton:

Auton<SND::DeviceHandler> handler;

(Note: the class Auton is documented in the project baselib)

This handler scans the hardware and provides the following information:

int no_of_palyer_devices = handler->getPlayers();
int no_of_recorder_devices = handler->getRecorders();

SND::Device * player = handler->getPlayer(player_index);        // 0 <= player_index < no_of_player_devices
SND::Device * recorder = handler->getRecorder(recorder_index);  // 0 <= recorder_index < no_of_recorder_devices

INSTANTIATE A PLAYER

3) Implement the sound frame handler virtual function of the player:

class MyPlayer: public SND::Player
{
    public:
        MyPlayer(SND::Device * dev):
            SND::Player(dev)
        {
        }

    private:
        virtual bool fillFrame(SND::BufferPtr & buf) override
        {
            // Fill the content of 'buf' here
            // (this is one sound frame)
            return true; // or false to stop playing
        }
};

MyPlayer player(handler->getPlayer(0));
player.setChannels(2).setSamplingRate(48000).Update();
player.Start();

Now you can hear the sound generated by the function fillFrame().

INSTANTIATE A RECORDER

3) Implement the sound frame handler virtual function of the recorder:

class MyRecorder: public SND::Recorder
{
    public:
        MyRecorder(SND::Device * dev):
            SND::Recorder(dev)
        {
        }

    private:
        virtual bool frameCaptured(SND::BufferPtr & buf) override
        {
            // Use the content of 'buf'
            // (this is one sound frame)
            return true; // or false to stop recording
        }
};

MyRecorder recorder(handler->getRecorder(0));
recorder.setChannels(2).setSamplingRate(48000).Update();
recorder.Start();

The function frameCaptured() will be called for each sound frame.
The SND::BufferPtr is a smart pointer. If you return it as is, then it will be used in
a ringbuffer. If you move its pointer out of it and return it as a null pointer, then
you can store the whole stream easily for further processing.

That's all.

HOW TO BUILD IT IN YOUR PROJECT

If you use makesys and put it in the right place (./modules directory), it is automatic.
If you have different build system, do the followings:

To build this library its include path must be added to the compiler.
Assuming you use gcc, these options are necessary:

-I/path/to/soundelf/include/public -I/path/to/soundelf/include/private -I/path/to/fftw/include

To use the library only one include file is necessary:

#include <device-interface.h>

which can be found on this path:
(gcc option)

-I/path/to/soundelf/include/public

For linking, the ALSA, FFTW, and pthread libraries must be used:
(gcc option)

-lfftw3f -lasound -lpthread
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.