Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions include/SFML/Audio/SoundBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.h>
#include <SFML/Audio/Types.h>
#include <SFML/Audio/SoundChannel.h>
#include <SFML/System/InputStream.h>
#include <SFML/System/Time.h>
#include <stddef.h>
Expand Down Expand Up @@ -84,15 +85,22 @@ CSFML_AUDIO_API sfSoundBuffer* sfSoundBuffer_createFromStream(sfInputStream* str
/// The assumed format of the audio samples is 16 bits signed integer
/// (int16_t).
///
/// \param samples Pointer to the array of samples in memory
/// \param sampleCount Number of samples in the array
/// \param channelCount Number of channels (1 = mono, 2 = stereo, ...)
/// \param sampleRate Sample rate (number of samples to play per second)
/// \param samples Pointer to the array of samples in memory
/// \param sampleCount Number of samples in the array
/// \param channelCount Number of channels (1 = mono, 2 = stereo, ...)
/// \param sampleRate Sample rate (number of samples to play per second)
/// \param channelMapData Pointer to the array of channel map data
/// \param channelMapSize Size of channel map data array
///
/// \return A new sfSoundBuffer object (NULL if failed)
///
////////////////////////////////////////////////////////////
CSFML_AUDIO_API sfSoundBuffer* sfSoundBuffer_createFromSamples(const int16_t* samples, uint64_t sampleCount, unsigned int channelCount, unsigned int sampleRate);
CSFML_AUDIO_API sfSoundBuffer* sfSoundBuffer_createFromSamples(const int16_t* samples,
uint64_t sampleCount,
unsigned int channelCount,
unsigned int sampleRate,
sfSoundChannel* channelMapData,
size_t channelMapSize);

////////////////////////////////////////////////////////////
/// \brief Create a new sound buffer by copying an existing one
Expand Down
65 changes: 65 additions & 0 deletions include/SFML/Audio/SoundChannel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////

#ifndef SFML_SOUNDCHANNEL_H
#define SFML_SOUNDCHANNEL_H


////////////////////////////////////////////////////////////
/// \brief Types of sound channels that can be read/written from sound buffers/files
///
/// In multi-channel audio, each sound channel can be
/// assigned a position. The position of the channel is
/// used to determine where to place a sound when it
/// is spatialised. Assigning an incorrect sound channel
/// will result in multi-channel audio being positioned
/// incorrectly when using spatialisation.
///
////////////////////////////////////////////////////////////
typedef enum
{
sfSoundChannelUnspecified,
sfSoundChannelMono,
sfSoundChannelFrontLeft,
sfSoundChannelFrontRight,
sfSoundChannelFrontCenter,
sfSoundChannelFrontLeftOfCenter,
sfSoundChannelFrontRightOfCenter,
sfSoundChannelLowFrequencyEffects,
sfSoundChannelBackLeft,
sfSoundChannelBackRight,
sfSoundChannelBackCenter,
sfSoundChannelSideLeft,
sfSoundChannelSideRight,
sfSoundChannelTopCenter,
sfSoundChannelTopFrontLeft,
sfSoundChannelTopFrontRight,
sfSoundChannelTopFrontCenter,
sfSoundChannelTopBackLeft,
sfSoundChannelTopBackRight,
sfSoundChannelTopBackCenter
} sfSoundChannel;


#endif // SFML_SOUNDCHANNEL_H
19 changes: 0 additions & 19 deletions include/SFML/Audio/SoundRecorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,6 @@ CSFML_AUDIO_API unsigned int sfSoundRecorder_getSampleRate(const sfSoundRecorder
////////////////////////////////////////////////////////////
CSFML_AUDIO_API bool sfSoundRecorder_isAvailable(void);

////////////////////////////////////////////////////////////
/// \brief Set the processing interval
///
/// The processing interval controls the period
/// between calls to the onProcessSamples function. You may
/// want to use a small interval if you want to process the
/// recorded data in real time, for example.
///
/// Note: this is only a hint, the actual period may vary.
/// So don't rely on this parameter to implement precise timing.
///
/// The default processing interval is 100 ms.
///
/// \param soundRecorder Sound recorder object
/// \param interval Processing interval
///
////////////////////////////////////////////////////////////
CSFML_AUDIO_API void sfSoundRecorder_setProcessingInterval(sfSoundRecorder* soundRecorder, sfTime interval);

////////////////////////////////////////////////////////////
/// \brief Get a list of the names of all available audio capture devices
///
Expand Down
24 changes: 15 additions & 9 deletions include/SFML/Audio/SoundStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
#include <SFML/Audio/Export.h>
#include <SFML/Audio/SoundStatus.h>
#include <SFML/Audio/Types.h>
#include <SFML/Audio/SoundChannel.h>
#include <SFML/System/Time.h>
#include <SFML/System/Vector3.h>
#include <stddef.h>


////////////////////////////////////////////////////////////
Expand All @@ -52,20 +54,24 @@ typedef void (*sfSoundStreamSeekCallback)(sfTime, void*); ///< T
////////////////////////////////////////////////////////////
/// \brief Create a new sound stream
///
/// \param onGetData Function called when the stream needs more data (can't be NULL)
/// \param onSeek Function called when the stream seeks (can't be NULL)
/// \param channelCount Number of channels to use (1 = mono, 2 = stereo)
/// \param sampleRate Sample rate of the sound (44100 = CD quality)
/// \param userData Data to pass to the callback functions
/// \param onGetData Function called when the stream needs more data (can't be NULL)
/// \param onSeek Function called when the stream seeks (can't be NULL)
/// \param channelCount Number of channels to use (1 = mono, 2 = stereo)
/// \param sampleRate Sample rate of the sound (44100 = CD quality)
/// \param channelMapData Pointer to the array of channel map data
/// \param channelMapSize Size of channel map data array
/// \param userData Data to pass to the callback functions
///
/// \return A new sfSoundStream object
///
////////////////////////////////////////////////////////////
CSFML_AUDIO_API sfSoundStream* sfSoundStream_create(sfSoundStreamGetDataCallback onGetData,
sfSoundStreamSeekCallback onSeek,
unsigned int channelCount,
unsigned int sampleRate,
void* userData);
sfSoundStreamSeekCallback onSeek,
unsigned int channelCount,
unsigned int sampleRate,
sfSoundChannel* channelMapData,
size_t channelMapSize,
void* userData);

////////////////////////////////////////////////////////////
/// \brief Destroy a sound stream
Expand Down
4 changes: 2 additions & 2 deletions include/SFML/Window/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ typedef enum
{
sfEvtClosed, ///< The window requested to be closed (no data)
sfEvtResized, ///< The window was resized (data in event.size)
sfEvtLostFocus, ///< The window lost the focus (no data)
sfEvtGainedFocus, ///< The window gained the focus (no data)
sfEvtFocusLost, ///< The window lost the focus (no data)
sfEvtFocusGained, ///< The window gained the focus (no data)
sfEvtTextEntered, ///< A character was entered (data in event.text)
sfEvtKeyPressed, ///< A key was pressed (data in event.key)
sfEvtKeyReleased, ///< A key was released (data in event.key)
Expand Down
12 changes: 10 additions & 2 deletions src/SFML/Audio/SoundBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,19 @@ sfSoundBuffer* sfSoundBuffer_createFromStream(sfInputStream* stream)


////////////////////////////////////////////////////////////
sfSoundBuffer* sfSoundBuffer_createFromSamples(const int16_t* samples, uint64_t sampleCount, unsigned int channelCount, unsigned int sampleRate)
sfSoundBuffer* sfSoundBuffer_createFromSamples(const int16_t* samples,
uint64_t sampleCount,
unsigned int channelCount,
unsigned int sampleRate,
sfSoundChannel* channelMapData,
size_t channelMapSize)
{
sfSoundBuffer* buffer = new sfSoundBuffer;

if (!buffer->This.loadFromSamples(samples, sampleCount, channelCount, sampleRate))
std::vector<sf::SoundChannel> channelMap(channelMapSize);
for (std::size_t i = 0; i < channelMap.size(); ++i)
channelMap[i] = static_cast<sf::SoundChannel>(channelMapData[i]);
if (!buffer->This.loadFromSamples(samples, sampleCount, channelCount, sampleRate, channelMap))
{
delete buffer;
buffer = nullptr;
Expand Down
7 changes: 0 additions & 7 deletions src/SFML/Audio/SoundRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,6 @@ bool sfSoundRecorder_isAvailable(void)
}


////////////////////////////////////////////////////////////
void sfSoundRecorder_setProcessingInterval(sfSoundRecorder* soundRecorder, sfTime interval)
{
CSFML_CALL(soundRecorder, setProcessingInterval(interval));
}


////////////////////////////////////////////////////////////
const char** sfSoundRecorder_getAvailableDevices(size_t* count)
{
Expand Down
5 changes: 0 additions & 5 deletions src/SFML/Audio/SoundRecorderStruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ public :
{
}

void setProcessingInterval(sfTime interval)
{
sf::SoundRecorder::setProcessingInterval(sf::microseconds(interval.microseconds));
}

private :

bool onStart() override
Expand Down
4 changes: 3 additions & 1 deletion src/SFML/Audio/SoundStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ sfSoundStream* sfSoundStream_create(sfSoundStreamGetDataCallback onGetData,
sfSoundStreamSeekCallback onSeek,
unsigned int channelCount,
unsigned int sampleRate,
sfSoundChannel* channelMapData,
size_t channelMapSize,
void* userData)
{
return new sfSoundStream(onGetData, onSeek, channelCount, sampleRate, userData);
return new sfSoundStream(onGetData, onSeek, channelCount, sampleRate, channelMapData, channelMapSize, userData);
}


Expand Down
12 changes: 10 additions & 2 deletions src/SFML/Audio/SoundStreamStruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/SoundChannel.h>
#include <SFML/Audio/SoundStream.hpp>


Expand All @@ -43,12 +44,17 @@ public :
sfSoundStreamSeekCallback onSeek,
unsigned int channelCount,
unsigned int sampleRate,
sfSoundChannel* channelMapData,
size_t channelMapSize,
void* userData) :
myGetDataCallback(onGetData),
mySeekCallback (onSeek),
myUserData (userData)
{
initialize(channelCount, sampleRate);
std::vector<sf::SoundChannel> channelMap(channelMapSize);
for (std::size_t i = 0; i < channelMap.size(); ++i)
channelMap[i] = static_cast<sf::SoundChannel>(channelMapData[i]);
initialize(channelCount, sampleRate, channelMap);
}

private :
Expand Down Expand Up @@ -88,8 +94,10 @@ struct sfSoundStream
sfSoundStreamSeekCallback onSeek,
unsigned int channelCount,
unsigned int sampleRate,
sfSoundChannel* channelMapData,
size_t channelMapSize,
void* userData) :
This(onGetData, onSeek, channelCount, sampleRate, userData)
This(onGetData, onSeek, channelCount, sampleRate, channelMapData, channelMapSize, userData)
{
}

Expand Down
Loading