Skip to content

Commit f48277f

Browse files
committed
brought back uint8_t for most 8bit samples
1 parent 9603c87 commit f48277f

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

AudioFile.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,10 @@ class AudioFile
212212

213213
//=============================================================
214214
int8_t sampleToSingleByte (T sample);
215+
public:
215216
T singleByteToSample (uint8_t sample);
216217
T singleByteToSample (int8_t sample);
217-
218+
private:
218219
uint32_t getAiffSampleRate (std::vector<uint8_t>& fileData, int sampleRateStartIndex);
219220
bool tenByteMatch (std::vector<uint8_t>& v1, int startIndex1, std::vector<uint8_t>& v2, int startIndex2);
220221
void addSampleRateToAiffData (std::vector<uint8_t>& fileData, uint32_t sampleRate);
@@ -945,7 +946,7 @@ bool AudioFile<T>::saveToWaveFile (std::string filePath)
945946
{
946947
if (bitDepth == 8)
947948
{
948-
int8_t byte = sampleToSingleByte (samples[channel][i]);
949+
uint8_t byte = sampleToSingleByte (samples[channel][i]);
949950
fileData.push_back (byte);
950951
}
951952
else if (bitDepth == 16)
@@ -1055,7 +1056,7 @@ bool AudioFile<T>::saveToAiffFile (std::string filePath)
10551056
{
10561057
if (bitDepth == 8)
10571058
{
1058-
int8_t byte = sampleToSingleByte (samples[channel][i]);
1059+
uint8_t byte = sampleToSingleByte (samples[channel][i]);
10591060
fileData.push_back (byte);
10601061
}
10611062
else if (bitDepth == 16)
@@ -1384,7 +1385,7 @@ T AudioFile<T>::singleByteToSample (uint8_t sample)
13841385
{
13851386
if (std::is_floating_point<T>::value)
13861387
{
1387-
return static_cast<T> (sample - 128) / static_cast<T> (128.);
1388+
return static_cast<T> (static_cast<int>(sample) - 128) / static_cast<T> (128.);
13881389
}
13891390

13901391
else if(std::numeric_limits<T>::is_integer)

tests/GeneralTests.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,17 @@ TEST_SUITE ("General Tests")
111111
CHECK_EQ (resampleIntegerSample<int8_t, int16_t>(-128), -32768);
112112
}
113113

114+
//=============================================================
115+
TEST_CASE ("GeneralTests::SingleByteToSample")
116+
{
117+
AudioFile<double> dummy;
118+
119+
CHECK_EQ (dummy.singleByteToSample((uint8_t)128), 0);
120+
CHECK_EQ (dummy.singleByteToSample((int8_t)0), 0);
121+
122+
CHECK (dummy.singleByteToSample((uint8_t)255) == doctest::Approx (1).epsilon (0.05));
123+
CHECK (dummy.singleByteToSample((uint8_t)0) == doctest::Approx (-1).epsilon (0.05));
124+
}
114125
//=============================================================
115126
TEST_CASE ("GeneralTests::IntegerFormat")
116127
{

0 commit comments

Comments
 (0)