2010-01-23 19:44:49 +00:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
Audacity: A Digital Audio Editor
|
|
|
|
|
2020-11-28 17:53:53 +00:00
|
|
|
@file SampleFormat.h
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
Dominic Mazzoni
|
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
#ifndef __AUDACITY_SAMPLE_FORMAT__
|
|
|
|
#define __AUDACITY_SAMPLE_FORMAT__
|
|
|
|
|
2021-05-09 15:16:56 +00:00
|
|
|
|
2018-11-11 02:40:37 +00:00
|
|
|
|
2016-04-14 04:46:48 +00:00
|
|
|
#include "MemoryX.h"
|
2010-01-23 19:44:49 +00:00
|
|
|
#include <wx/defs.h>
|
|
|
|
|
The fabled realtime effects...
I've made it where you can enable and disable via experimentals:
EXPERIMENTAL_REALTIME_EFFECTS
EXPERIMENTAL_EFFECTS_RACK
You will notice that, as of now, the only effects currently set up for
realtime are VSTs. Now that this is in, I will start converting the
rest.
As I start to convert the effects, the astute of you may notice that
they no longer directly access tracks or any "internal" Audacity
objects. This isolates the effects from changes in Audacity and makes
it much easier to add new ones.
Anyway, all 3 platforms can now display VST effects in graphical mode.
Yes, that means Linux too. There are quite a few VSTs for Linux if
you search for them.
The so-called "rack" definitely needs some discussion, work, and attention
from someone much better at graphics than me. I'm not really sure it should
stay in as-is. I'd originally planned for it to be simply a utility window
where you can store your (preconfigured) favorite effects. It should probably
revert back to that idea.
You may notice that this DOES include the API work I did. The realtime effects
were too tied to it and I didn't want to redo the whole thing. As I mentioned
elsewhere, the API stuff may or may not be very future proof.
So, let the critter complaints commence. I absolute KNOW there will be some.
(I know I'll be hearing from the Linux peeps pretty darn quickly. ;-))
2014-10-26 03:24:10 +00:00
|
|
|
#include "audacity/Types.h"
|
2020-11-28 17:53:53 +00:00
|
|
|
#include "Dither.h"
|
The fabled realtime effects...
I've made it where you can enable and disable via experimentals:
EXPERIMENTAL_REALTIME_EFFECTS
EXPERIMENTAL_EFFECTS_RACK
You will notice that, as of now, the only effects currently set up for
realtime are VSTs. Now that this is in, I will start converting the
rest.
As I start to convert the effects, the astute of you may notice that
they no longer directly access tracks or any "internal" Audacity
objects. This isolates the effects from changes in Audacity and makes
it much easier to add new ones.
Anyway, all 3 platforms can now display VST effects in graphical mode.
Yes, that means Linux too. There are quite a few VSTs for Linux if
you search for them.
The so-called "rack" definitely needs some discussion, work, and attention
from someone much better at graphics than me. I'm not really sure it should
stay in as-is. I'd originally planned for it to be simply a utility window
where you can store your (preconfigured) favorite effects. It should probably
revert back to that idea.
You may notice that this DOES include the API work I did. The realtime effects
were too tied to it and I didn't want to redo the whole thing. As I mentioned
elsewhere, the API stuff may or may not be very future proof.
So, let the critter complaints commence. I absolute KNOW there will be some.
(I know I'll be hearing from the Linux peeps pretty darn quickly. ;-))
2014-10-26 03:24:10 +00:00
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
//
|
|
|
|
// Definitions / Meta-Information
|
|
|
|
//
|
|
|
|
|
2020-11-28 17:53:53 +00:00
|
|
|
//! These global variables are assigned at application startup or after change of preferences.
|
|
|
|
extern AUDACITY_DLL_API DitherType gLowQualityDither, gHighQualityDither;
|
|
|
|
|
The fabled realtime effects...
I've made it where you can enable and disable via experimentals:
EXPERIMENTAL_REALTIME_EFFECTS
EXPERIMENTAL_EFFECTS_RACK
You will notice that, as of now, the only effects currently set up for
realtime are VSTs. Now that this is in, I will start converting the
rest.
As I start to convert the effects, the astute of you may notice that
they no longer directly access tracks or any "internal" Audacity
objects. This isolates the effects from changes in Audacity and makes
it much easier to add new ones.
Anyway, all 3 platforms can now display VST effects in graphical mode.
Yes, that means Linux too. There are quite a few VSTs for Linux if
you search for them.
The so-called "rack" definitely needs some discussion, work, and attention
from someone much better at graphics than me. I'm not really sure it should
stay in as-is. I'd originally planned for it to be simply a utility window
where you can store your (preconfigured) favorite effects. It should probably
revert back to that idea.
You may notice that this DOES include the API work I did. The realtime effects
were too tied to it and I didn't want to redo the whole thing. As I mentioned
elsewhere, the API stuff may or may not be very future proof.
So, let the critter complaints commence. I absolute KNOW there will be some.
(I know I'll be hearing from the Linux peeps pretty darn quickly. ;-))
2014-10-26 03:24:10 +00:00
|
|
|
#if 0
|
|
|
|
// Moved to audacity/types.h
|
2010-01-23 19:44:49 +00:00
|
|
|
typedef enum {
|
|
|
|
int16Sample = 0x00020001,
|
|
|
|
int24Sample = 0x00040001,
|
|
|
|
floatSample = 0x0004000F
|
|
|
|
} sampleFormat;
|
|
|
|
|
The fabled realtime effects...
I've made it where you can enable and disable via experimentals:
EXPERIMENTAL_REALTIME_EFFECTS
EXPERIMENTAL_EFFECTS_RACK
You will notice that, as of now, the only effects currently set up for
realtime are VSTs. Now that this is in, I will start converting the
rest.
As I start to convert the effects, the astute of you may notice that
they no longer directly access tracks or any "internal" Audacity
objects. This isolates the effects from changes in Audacity and makes
it much easier to add new ones.
Anyway, all 3 platforms can now display VST effects in graphical mode.
Yes, that means Linux too. There are quite a few VSTs for Linux if
you search for them.
The so-called "rack" definitely needs some discussion, work, and attention
from someone much better at graphics than me. I'm not really sure it should
stay in as-is. I'd originally planned for it to be simply a utility window
where you can store your (preconfigured) favorite effects. It should probably
revert back to that idea.
You may notice that this DOES include the API work I did. The realtime effects
were too tied to it and I didn't want to redo the whole thing. As I mentioned
elsewhere, the API stuff may or may not be very future proof.
So, let the critter complaints commence. I absolute KNOW there will be some.
(I know I'll be hearing from the Linux peeps pretty darn quickly. ;-))
2014-10-26 03:24:10 +00:00
|
|
|
/** \brief Return the size (in memory) of one sample (bytes) */
|
2016-09-06 11:40:49 +00:00
|
|
|
#define SAMPLE_SIZE(SampleFormat) ( size_t{ (SampleFormat) >> 16 } )
|
The fabled realtime effects...
I've made it where you can enable and disable via experimentals:
EXPERIMENTAL_REALTIME_EFFECTS
EXPERIMENTAL_EFFECTS_RACK
You will notice that, as of now, the only effects currently set up for
realtime are VSTs. Now that this is in, I will start converting the
rest.
As I start to convert the effects, the astute of you may notice that
they no longer directly access tracks or any "internal" Audacity
objects. This isolates the effects from changes in Audacity and makes
it much easier to add new ones.
Anyway, all 3 platforms can now display VST effects in graphical mode.
Yes, that means Linux too. There are quite a few VSTs for Linux if
you search for them.
The so-called "rack" definitely needs some discussion, work, and attention
from someone much better at graphics than me. I'm not really sure it should
stay in as-is. I'd originally planned for it to be simply a utility window
where you can store your (preconfigured) favorite effects. It should probably
revert back to that idea.
You may notice that this DOES include the API work I did. The realtime effects
were too tied to it and I didn't want to redo the whole thing. As I mentioned
elsewhere, the API stuff may or may not be very future proof.
So, let the critter complaints commence. I absolute KNOW there will be some.
(I know I'll be hearing from the Linux peeps pretty darn quickly. ;-))
2014-10-26 03:24:10 +00:00
|
|
|
#endif
|
|
|
|
|
2012-03-25 16:19:08 +00:00
|
|
|
// Used to determine how to fill in empty areas of audio.
|
|
|
|
typedef enum {
|
|
|
|
fillZero = 0,
|
|
|
|
fillTwo = 2
|
|
|
|
}fillFormat;
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
/** \brief Return the size on disk of one uncompressed sample (bytes) */
|
2016-09-06 11:40:49 +00:00
|
|
|
#define SAMPLE_SIZE_DISK(SampleFormat) (((SampleFormat) == int24Sample) ? \
|
|
|
|
size_t{ 3 } : SAMPLE_SIZE(SampleFormat) )
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2020-09-28 12:50:18 +00:00
|
|
|
AUDACITY_DLL_API TranslatableString GetSampleFormatStr(sampleFormat format);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Allocating/Freeing Samples
|
|
|
|
//
|
|
|
|
|
2015-03-28 18:46:40 +00:00
|
|
|
class SampleBuffer {
|
|
|
|
|
|
|
|
public:
|
|
|
|
SampleBuffer()
|
2016-02-01 15:16:00 +00:00
|
|
|
: mPtr(0)
|
2015-03-28 18:46:40 +00:00
|
|
|
{}
|
2016-09-06 13:19:27 +00:00
|
|
|
SampleBuffer(size_t count, sampleFormat format)
|
2017-02-25 23:13:05 +00:00
|
|
|
: mPtr((samplePtr)malloc(count * SAMPLE_SIZE(format)))
|
2015-03-28 18:46:40 +00:00
|
|
|
{}
|
|
|
|
~SampleBuffer()
|
|
|
|
{
|
|
|
|
Free();
|
|
|
|
}
|
|
|
|
|
|
|
|
// WARNING! May not preserve contents.
|
2016-09-06 13:19:27 +00:00
|
|
|
SampleBuffer &Allocate(size_t count, sampleFormat format)
|
2015-03-28 18:46:40 +00:00
|
|
|
{
|
2016-02-01 15:16:00 +00:00
|
|
|
Free();
|
2017-02-25 23:13:05 +00:00
|
|
|
mPtr = (samplePtr)malloc(count * SAMPLE_SIZE(format));
|
2016-02-01 15:16:00 +00:00
|
|
|
return *this;
|
2015-03-28 18:46:40 +00:00
|
|
|
}
|
|
|
|
|
2016-02-01 15:16:00 +00:00
|
|
|
|
2015-03-28 18:46:40 +00:00
|
|
|
void Free()
|
|
|
|
{
|
2017-02-25 23:13:05 +00:00
|
|
|
free(mPtr);
|
2015-03-28 18:46:40 +00:00
|
|
|
mPtr = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
samplePtr ptr() const { return mPtr; }
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
2015-05-29 18:09:48 +00:00
|
|
|
samplePtr mPtr;
|
2015-03-28 18:46:40 +00:00
|
|
|
};
|
|
|
|
|
2016-02-01 15:16:00 +00:00
|
|
|
class GrowableSampleBuffer : private SampleBuffer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GrowableSampleBuffer()
|
|
|
|
: SampleBuffer()
|
|
|
|
, mCount(0)
|
|
|
|
{}
|
|
|
|
|
2016-09-06 13:19:27 +00:00
|
|
|
GrowableSampleBuffer(size_t count, sampleFormat format)
|
2016-02-01 15:16:00 +00:00
|
|
|
: SampleBuffer(count, format)
|
|
|
|
, mCount(count)
|
|
|
|
{}
|
|
|
|
|
2016-09-06 13:19:27 +00:00
|
|
|
GrowableSampleBuffer &Resize(size_t count, sampleFormat format)
|
2016-02-01 15:16:00 +00:00
|
|
|
{
|
|
|
|
if (!ptr() || mCount < count) {
|
|
|
|
Allocate(count, format);
|
|
|
|
mCount = count;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Free()
|
|
|
|
{
|
|
|
|
SampleBuffer::Free();
|
|
|
|
mCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
using SampleBuffer::ptr;
|
|
|
|
|
|
|
|
private:
|
2016-09-06 13:19:27 +00:00
|
|
|
size_t mCount;
|
2016-02-01 15:16:00 +00:00
|
|
|
};
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
//
|
|
|
|
// Copying, Converting and Clearing Samples
|
|
|
|
//
|
|
|
|
|
2020-11-28 02:06:39 +00:00
|
|
|
AUDACITY_DLL_API
|
|
|
|
//! Copy samples from any format into the widest format, which is 32 bit float, with no dithering
|
|
|
|
/*!
|
|
|
|
@param src address of source samples
|
|
|
|
@param srcFormat format of source samples, determines sizeof each one
|
|
|
|
@param dst address of floating-point numbers
|
|
|
|
@param len count of samples to copy
|
|
|
|
@param srcStride how many samples to advance src after copying each one
|
|
|
|
@param dstString how many samples to advance dst after copying each one
|
|
|
|
*/
|
|
|
|
void SamplesToFloats(constSamplePtr src, sampleFormat srcFormat,
|
|
|
|
float *dst, size_t len, size_t srcStride = 1, size_t dstStride = 1);
|
|
|
|
|
2020-09-28 12:50:18 +00:00
|
|
|
AUDACITY_DLL_API
|
2020-11-28 17:53:53 +00:00
|
|
|
//! Copy samples from any format to any other format; apply dithering only if narrowing the format
|
|
|
|
/*!
|
|
|
|
@copydetails SamplesToFloats()
|
|
|
|
@param dstFormat format of destination samples, determines sizeof each one
|
|
|
|
@param ditherType choice of dithering algorithm to use if narrowing the format
|
|
|
|
*/
|
|
|
|
void CopySamples(constSamplePtr src, sampleFormat srcFormat,
|
|
|
|
samplePtr dst, sampleFormat dstFormat, size_t len,
|
|
|
|
DitherType ditherType = gHighQualityDither, //!< default is loaded from a global variable
|
|
|
|
unsigned int srcStride=1, unsigned int dstStride=1);
|
2014-06-03 20:30:19 +00:00
|
|
|
|
2020-09-28 12:50:18 +00:00
|
|
|
AUDACITY_DLL_API
|
2010-01-23 19:44:49 +00:00
|
|
|
void ClearSamples(samplePtr buffer, sampleFormat format,
|
2016-09-04 20:07:17 +00:00
|
|
|
size_t start, size_t len);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2020-09-28 12:50:18 +00:00
|
|
|
AUDACITY_DLL_API
|
2015-04-16 21:35:58 +00:00
|
|
|
void ReverseSamples(samplePtr buffer, sampleFormat format,
|
|
|
|
int start, int len);
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
//
|
2016-02-13 15:43:16 +00:00
|
|
|
// This must be called on startup and everytime NEW ditherers
|
2010-01-23 19:44:49 +00:00
|
|
|
// are set in preferences.
|
|
|
|
//
|
|
|
|
|
2020-09-28 12:50:18 +00:00
|
|
|
AUDACITY_DLL_API
|
2010-01-23 19:44:49 +00:00
|
|
|
void InitDitherers();
|
|
|
|
|
2016-04-14 04:46:48 +00:00
|
|
|
// These are so commonly done for processing samples in floating point form in memory,
|
2020-04-11 07:08:33 +00:00
|
|
|
// let's have abbreviations.
|
2016-04-14 04:46:48 +00:00
|
|
|
using Floats = ArrayOf<float>;
|
|
|
|
using FloatBuffers = ArraysOf<float>;
|
|
|
|
using Doubles = ArrayOf<double>;
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
#endif
|