ソースを参照

Add AudioEffectMidSide (thanks Hedde Bosman)

dds
PaulStoffregen 9年前
コミット
e6de507e74
3個のファイルの変更147行の追加0行の削除
  1. +92
    -0
      effect_midside.cpp
  2. +51
    -0
      effect_midside.h
  3. +4
    -0
      keywords.txt

+ 92
- 0
effect_midside.cpp ファイルの表示

@@ -0,0 +1,92 @@
/* Audio Library for Teensy 3.X
* Copyright (c) 2015, Hedde Bosman
*
* Development of this audio library was funded by PJRC.COM, LLC by sales of
* Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop
* open source software by purchasing Teensy or other PJRC products.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice, development funding notice, and this permission
* notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#include "effect_midside.h"

void AudioEffectMidSide::update(void)
{
audio_block_t *blocka, *blockb;

uint32_t *pa, *pb, *end;
uint32_t a12, a34; //, a56, a78;
uint32_t b12, b34; //, b56, b78;

blocka = receiveWritable(0); // left (encoding) or mid (decoding)
blockb = receiveWritable(1); // right (encoding) or side (decoding)
if (!blocka || !blockb) {
if (blocka) release(blocka); // maybe an extra if statement here but if one
if (blockb) release(blockb); // of the blocks is NULL then it's trouble anyway
return;
}

pa = (uint32_t *)(blocka->data);
pb = (uint32_t *)(blockb->data);
end = pa + AUDIO_BLOCK_SAMPLES/2;

if (encoding) {
while (pa < end) {
// mid[i] = (blocka[i] + blockb[i])/2; // div2 to prevent overflows
// side[i] = (blocka[i] - blockb[i])/2; // div2 to prevent overflows
// L[i] = (mid[i] + side[i])/2;
// R[i] = (mid[i] - side[i])/2;
a12 = signed_halving_add_16_and_16(*pa, *pb); // mid12
a34 = signed_halving_add_16_and_16(*(pa+1), *(pb+1)); //mid34
b12 = signed_halving_subtract_16_and_16(*pa, *pb); // side12
b34 = signed_halving_subtract_16_and_16(*(pa+1), *(pb+1)); // side34
*pa++ = a12;
*pa++ = a34;
*pb++ = b12;
*pb++ = b34;
}
} else {
while (pa < end) {
// L[i] = mid[i] + side[i]);
// R[i] = mid[i] - side[i]);
// Because the /2 has already been applied in the encoding,
// we shouldn't have to add it here.
// However... because of the posibility that the user has
// modified mid or side such that
// it could overflow, we have to:
// a) preventively do a (x/2+y/2)*2 again, causing bit reduction
// or b) perform saturation or something.
// While (b) could produce artifacts if saturated, I'll go for
// that option to preserve precision
// QADD16 and QSUB16 perform saturating add/sub
a12 = signed_add_16_and_16(*pa, *pb); // left12
a34 = signed_add_16_and_16(*(pa+1), *(pb+1)); // left34
b12 = signed_subtract_16_and_16(*pa, *pb); // right12
b34 = signed_subtract_16_and_16(*(pa+1), *(pb+1)); // right34
*pa++ = a12;
*pa++ = a34;
*pb++ = b12;
*pb++ = b34;
}
}
transmit(blocka, 0); // mid (encoding) or left (decoding)
transmit(blockb, 1); // side (encoding) or right (decoding)
release(blocka);
release(blockb);
}

+ 51
- 0
effect_midside.h ファイルの表示

@@ -0,0 +1,51 @@
/* Audio Library for Teensy 3.X
* Copyright (c) 2015, Hedde Bosman
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef effect_midside_decode_h_
#define effect_midside_decode_h_

#include "AudioStream.h"

#include "utility/dspinst.h"


/**
* This object performs the decoding of mid/side signals into a stereo signal.
* That is, left = (mid+side), right = (mid-side)
* After encoding and processing, this object decodes the mid/side components
* back into enjoyable stereo audio.
* Caution: processed mid/side signals may cause digital saturation (clipping).
***************************************************************/
class AudioEffectMidSide : public AudioStream
{
public:
AudioEffectMidSide(void): AudioStream(2,inputQueueArray), encoding(true) { }
void encode() { encoding = true; }
void decode() { encoding = false; }
virtual void update(void);
private:
bool encoding;
audio_block_t *inputQueueArray[2];
};

#endif


+ 4
- 0
keywords.txt ファイルの表示

@@ -27,6 +27,7 @@ AudioEffectMultiply KEYWORD2
AudioEffectDelay KEYWORD2
AudioEffectDelayExternal KEYWORD2
AudioEffectBitcrusher KEYWORD2
AudioEffectMidSide KEYWORD2
AudioFilterBiquad KEYWORD2
AudioFilterFIR KEYWORD2
AudioFilterStateVariable KEYWORD2
@@ -66,6 +67,7 @@ frequency KEYWORD2
phase KEYWORD2
amplitude KEYWORD2
offset KEYWORD2
readPeakToPeak KEYWORD2
pulseWidth KEYWORD2
resonance KEYWORD2
octaveControl KEYWORD2
@@ -128,6 +130,8 @@ sampleRate KEYWORD2
bits KEYWORD2
mute_PCM KEYWORD2
probability KEYWORD2
encode KEYWORD2
decode KEYWORD2

AudioMemoryUsage KEYWORD2
AudioMemoryUsageMax KEYWORD2

読み込み中…
キャンセル
保存