Skip to content

Commit

Permalink
solve bug: make shared array unique to instances in blade enc
Browse files Browse the repository at this point in the history
  • Loading branch information
ArdenButterfield committed Oct 7, 2023
1 parent 2fac72f commit 49d1f50
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Source/GUIelements/TitlePanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void TitlePanel::paint (juce::Graphics& g)

g.setColour (MaimColours::CONTRAST_COLOR_LIGHT);
g.setFont(title_font);
g.drawText ("MAIM", textRect,
g.drawText ("MAIM", textRect.withTrimmedRight(4).withTrimmedTop(4),
juce::Justification::centredTop, true);
g.setFont(tooltip_font);
g.setColour(MaimColours::BEVEL_BLACK);
Expand Down
10 changes: 9 additions & 1 deletion Source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ MaimAudioProcessor::MaimAudioProcessor()
mp3ControllerManager(parameters),
dryWetMixer(std::max(BLADELATENCYSAMPLES, LAMELATENCYSAMPLES))
{
std::cout << this << " constructor\n";
oldPreGain = 1;
oldPostGain = 1;

Expand Down Expand Up @@ -230,6 +231,8 @@ void MaimAudioProcessor::changeProgramName (int index, const juce::String& newNa
//==============================================================================
void MaimAudioProcessor::prepareToPlay (double fs, int samplesPerBlock)
{
std::cout << this << " prepare to play\n";

setLatencySamples(currentLatencySamples());
dryWetMixer.prepare({fs, static_cast<uint32_t>(samplesPerBlock), 2});
sampleRate = fs;
Expand Down Expand Up @@ -273,6 +276,8 @@ bool MaimAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) con

void MaimAudioProcessor::updateParameters()
{
std::cout << this << " update params\n";

auto hicut = ((juce::AudioParameterFloat*)parameters.getParameter("hicut"))->get();
auto locut = ((juce::AudioParameterFloat*)parameters.getParameter("locut"))->get();
hicut = std::max(1.f, std::min(hicut, (float)sampleRate / 2 - 1));
Expand Down Expand Up @@ -333,6 +338,7 @@ void MaimAudioProcessor::processBlockStereo (juce::AudioBuffer<float>& buffer)
void MaimAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer,
juce::MidiBuffer& midiMessages)
{
// std::cout << this << " process block\n";

if (parametersNeedUpdating) {
updateParameters();
Expand Down Expand Up @@ -368,6 +374,7 @@ juce::AudioProcessorEditor* MaimAudioProcessor::createEditor()
//==============================================================================
void MaimAudioProcessor::getStateInformation (juce::MemoryBlock& destData)
{
std::cout << this << " get state\n";

auto state = parameters.copyState();
for (const juce::String parameterName : {"psychoanal", "mdct"}) {
Expand All @@ -384,7 +391,8 @@ void MaimAudioProcessor::getStateInformation (juce::MemoryBlock& destData)
}
void MaimAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
{

std::cout << this << " set state\n";

std::unique_ptr<juce::XmlElement> xmlState (getXmlFromBinary (data, sizeInBytes));

if (xmlState.get() != nullptr) {
Expand Down
4 changes: 4 additions & 0 deletions Source/lib/blade/bladeenc/blade.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ encoder_flags_and_data* blade_init(int samplerate, int bitrate)
flags->codec_data.fCopyright = 0;
flags->codec_data.fOriginal = 1;

flags->gr_idx[0] = 0;
flags->gr_idx[1] = 1;
flags->gr_idx[2] = 2;

codecInit(flags, &(flags->codec_data));
// we don't need the return value, because its already stored in flags.

Expand Down
2 changes: 1 addition & 1 deletion Source/lib/blade/bladeenc/codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ unsigned int codecEncodeChunk

for (gr = 0; gr < 2; gr++)
{
int gr_plus_1 = gr_idx[gr+1];
int gr_plus_1 = flags->gr_idx[gr+1];

for (ch = 0; ch < flags->stereo; ch++)
{
Expand Down
3 changes: 3 additions & 0 deletions Source/lib/blade/bladeenc/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,9 @@ typedef struct encoder_flags_and_data_struct {
Header *pHeaderChain;
Header *pFreeHeaderChain;

// mdct
int gr_idx[3];

} encoder_flags_and_data;

#if defined(__cplusplus)
Expand Down
10 changes: 0 additions & 10 deletions Source/lib/blade/bladeenc/formatbitstream2.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,6 @@
#include "formatbitstream2.h"





extern char *pEncodedOutput;
extern int outputBit;





/*____ Structure Definitions _________________________________________________*/

// header struct moved to common.h
Expand Down
15 changes: 8 additions & 7 deletions Source/lib/blade/bladeenc/mdct.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@
/*
This is table B.9: coefficients for aliasing reduction
*/
static double c[8] = { -0.6, -0.535, -0.33, -0.185, -0.095, -0.041, -0.0142, -0.0037 };
const double c[8] = { -0.6, -0.535, -0.33, -0.185, -0.095, -0.041, -0.0142, -0.0037 };





int gr_idx[3] = {0,1,2};
// int gr_idx[3] = {0,1,2};



Expand Down Expand Up @@ -118,8 +118,8 @@ void mdct_sub
flags->bends.in_short_block = 0;
for (gr = 0; gr < mode_gr; gr++)
{
int pre_gr = gr_idx[gr ];
int cur_gr = gr_idx[gr+1];
int pre_gr = flags->gr_idx[gr ];
int cur_gr = flags->gr_idx[gr+1];

for (ch = 0; ch < stereo; ch++)
{
Expand Down Expand Up @@ -188,10 +188,11 @@ void mdct_sub
Save latest granule's subband samples to be used in
the next mdct call
*/
j = gr_idx[mode_gr];
j = flags->gr_idx[mode_gr];
for (k = mode_gr; k > 0; k--)
gr_idx[k] = gr_idx[k-1];
gr_idx[0] = j;
flags->gr_idx[k] = flags->gr_idx[k-1];
flags->gr_idx[0] = j;
// printf("%i %i %i\n", gr_idx[0], gr_idx[1], gr_idx[2]);
}


Expand Down
2 changes: 1 addition & 1 deletion Source/lib/blade/bladeenc/mdct.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extern int fInit_mdct_sub;
extern int fInit_mdct;


extern int gr_idx[3];
// extern int gr_idx[3];



Expand Down

0 comments on commit 49d1f50

Please sign in to comment.