| 87 | } |
| 88 | |
| 89 | void OggVorbisEncoder::Write(uint8* samples, uint32 numSamples) |
| 90 | { |
| 91 | static const uint32 WRITE_LENGTH = 1024; |
| 92 | |
| 93 | uint32 numFrames = numSamples / _numChannels; |
| 94 | while (numFrames > 0) |
| 95 | { |
| 96 | const uint32 numFramesToWrite = Math::Min(numFrames, WRITE_LENGTH); |
| 97 | float** buffer = vorbis_analysis_buffer(&_vorbisState, numFramesToWrite); |
| 98 | |
| 99 | if (_bitDepth == 8) |
| 100 | { |
| 101 | for (uint32 i = 0; i < numFramesToWrite; i++) |
| 102 | { |
| 103 | for (uint32 j = 0; j < _numChannels; j++) |
| 104 | { |
| 105 | const int8 sample = *(int8*)samples; |
| 106 | const float encodedSample = sample / 127.0f; |
| 107 | buffer[j][i] = encodedSample; |
| 108 | |
| 109 | samples++; |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | else if (_bitDepth == 16) |
| 114 | { |
| 115 | for (uint32 i = 0; i < numFramesToWrite; i++) |
| 116 | { |
| 117 | for (uint32 j = 0; j < _numChannels; j++) |
| 118 | { |
| 119 | const int16 sample = *(int16*)samples; |
| 120 | const float encodedSample = sample / 32767.0f; |
| 121 | buffer[j][i] = encodedSample; |
| 122 | |
| 123 | samples += 2; |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | else if (_bitDepth == 24) |
| 128 | { |
| 129 | for (uint32 i = 0; i < numFramesToWrite; i++) |
| 130 | { |
| 131 | for (uint32 j = 0; j < _numChannels; j++) |
| 132 | { |
| 133 | const int32 sample = AudioTool::Convert24To32Bits(samples); |
| 134 | const float encodedSample = sample / 2147483647.0f; |
| 135 | buffer[j][i] = encodedSample; |
| 136 | |
| 137 | samples += 3; |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | else if (_bitDepth == 32) |
| 142 | { |
| 143 | for (uint32 i = 0; i < numFramesToWrite; i++) |
| 144 | { |
| 145 | for (uint32 j = 0; j < _numChannels; j++) |
| 146 | { |
no test coverage detected