Skip to content

Commit

Permalink
opus controller added, still no functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
ArdenButterfield committed Aug 30, 2024
1 parent 915b953 commit db8ec78
Show file tree
Hide file tree
Showing 20 changed files with 179 additions and 203 deletions.
19 changes: 13 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,22 +153,22 @@ set(SourceFiles
Source/GUIelements/ArrayAssignerButtons/ArrayAssignerButton.h
Source/GUIelements/MaimColours.h
Source/MP3ControllerManager.cpp
Source/BladeController.h
Source/CodecControllers/BladeController.h
Source/MP3ControllerManager.h
Source/PluginProcessor.cpp
Source/MP3Controller.cpp
Source/CodecControllers/MP3Controller.cpp
Source/QueueBuffer.h
Source/RootMeanSquare.cpp
Source/PluginEditor.h
Source/RootMeanSquare.h
Source/AutoGain.cpp
Source/PluginEditor.cpp
Source/LameController.h
Source/CodecControllers/LameController.h
Source/AutoGain.h
Source/LameController.cpp
Source/CodecControllers/LameController.cpp
Source/PluginProcessor.h
Source/BladeController.cpp
Source/MP3Controller.h
Source/CodecControllers/BladeController.cpp
Source/CodecControllers/MP3Controller.h
)
target_include_directories("${PROJECT_NAME}"
PRIVATE
Expand Down Expand Up @@ -250,6 +250,13 @@ target_link_libraries("${PROJECT_NAME}"
juce::juce_dsp
)

add_custom_target(
lame_lib
COMMAND make
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/Source/lib/lame"
)

add_dependencies("${PROJECT_NAME}" lame_lib)


# When present, use Intel IPP for performance on Windows
Expand Down
4 changes: 3 additions & 1 deletion Docs/BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ git clone --recurse-submodules https://github.com/ArdenButterfield/Maim
3. so even if you have LAME installed already, you still need to do this step.

```sh
cd Fish/Source/lib/lame/
cd Maim/Source/lib/lame/
./configure CFLAGS="-fPIC" --disable-frontend --enable-expopt=full --disable-shared --enable-static
make
cd ../../..
```

Optionally, add `--enable-debug` to the `configure` command, to compile with `-g`.

3. Build the plugin. You can change `Release` to `Debug` in both lines to change the build configuration to one without optimization.

```sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void BladeController::setBitrateSquishBends(float squish)
blade_set_bitrate_squish_bends(blade_encoder, (1 - squish) * (1 - squish) * (1 - squish));
}

void BladeController::_setThresholdBias(float bias)
void BladeController::setThresholdBias(float bias)
{
blade_set_threshold_bias_bends(blade_encoder, bias);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

#pragma once
#include "lib/blade/bladeenc/blade.h"
#include "../lib/blade/bladeenc/blade.h"

#include "MP3Controller.h"

Expand All @@ -32,7 +32,7 @@ class BladeController : public MP3Controller
void setMDCTwindowincrBends(int window_incr) override;
void setMDCTBandReassignmentBends(int* order) override;
void setBitrateSquishBends(float squish) override;
void _setThresholdBias(float bias) override;
void setThresholdBias(float bias) override;
void setMDCTfeedback(float feedback) override;

float* getPsychoanalThreshold() override;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ class CodecController
virtual void setMDCTwindowincrBends(int window_incr) = 0;
virtual void setMDCTBandReassignmentBends(int* order) = 0;
virtual void setBitrateSquishBends(float squish) = 0;
virtual void _setThresholdBias(float bias) = 0;
virtual void setThresholdBias(float bias) { _setThresholdBias(bias); }
virtual void setThresholdBias(float bias) = 0;
virtual void setMDCTfeedback(float feedback) = 0;

virtual float* getPsychoanalThreshold() = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void LameController::setBitrateSquishBends(float squish)
lame_set_bitrate_squish_bends(lame_enc_handler, (1 - squish) * (1 - squish) * (1 - squish));
}

void LameController::_setThresholdBias(float bias)
void LameController::setThresholdBias(float bias)
{
lame_set_threshold_bias_bends(lame_enc_handler, bias);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class LameController : public MP3Controller
void setMDCTwindowincrBends(int window_incr) override;
void setMDCTBandReassignmentBends(int* order) override;
void setBitrateSquishBends(float squish) override;
void _setThresholdBias(float bias) override;
void setThresholdBias(float bias) override;
void setMDCTfeedback(float feedback) override;

float* getPsychoanalThreshold() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,21 @@ bool MP3Controller::processFrame (float* leftIn, float* rightIn, float* leftOut,
}
return true;
}

void MP3Controller::setThresholdBias (float bias)
int MP3Controller::getClosest (const int target, const std::vector<int>& options)
{
_setThresholdBias(bias);
}
auto lower = options[0];
auto upper = options[options.size() - 1];
for (const auto option : options)
{
if (option < target)
{
lower = option;
}
else
{
upper = option;
return (target - lower) < (upper - target) ? lower : upper;
}
}
return lower;
}
24 changes: 3 additions & 21 deletions Source/MP3Controller.h → Source/CodecControllers/MP3Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

#include "juce_core/juce_core.h"

#include <lame.h>
#include "lame.h"

#include "QueueBuffer.h"
#include "../QueueBuffer.h"
#include "CodecController.h"

class MP3Controller : public CodecController
Expand All @@ -39,7 +39,6 @@ class MP3Controller : public CodecController
void deInit() override;
bool processFrame(float* leftIn, float* rightIn, float* leftOut, float* rightOut) override;

void setThresholdBias(float bias) override;

std::string name;
static const int MP3FRAMESIZE = 1152;
Expand Down Expand Up @@ -71,24 +70,7 @@ class MP3Controller : public CodecController
int input_buf_size;
int mp3_buf_size;

int getClosest(const int target, const std::vector<int>& options)
{
auto lower = options[0];
auto upper = options[options.size() - 1];
for (const auto option : options)
{
if (option < target)
{
lower = option;
}
else
{
upper = option;
return (target - lower) < (upper - target) ? lower : upper;
}
}
return lower;
}
static int getClosest(int target, const std::vector<int>& options);
#if WRITETODEBUGMP3FILE
juce::File debugFile;
#endif
Expand Down
5 changes: 5 additions & 0 deletions Source/CodecControllers/OpusController.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//
// Created by arden on 8/27/24.
//

#include "OpusController.h"
67 changes: 67 additions & 0 deletions Source/CodecControllers/OpusController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// Created by arden on 8/27/24.
//

#ifndef MAIM_OPUSCONTROLLER_H
#define MAIM_OPUSCONTROLLER_H

#include "CodecController.h"
#include "opus.h"

class OpusController : public CodecController {
public:
OpusController() : bInitialized(false) {};
~OpusController() override = default;

bool init(int sampleRate,
int maxSamplesPerBlock,
int bitrate
) override {
return true;
}
void deInit() override {}
bool processFrame(float* leftIn, float* rightIn, float* leftOut, float* rightOut) override {
return true;
}

int getBitrate() override { return bitrate; }
void setButterflyBends(float buinbu, float buinbd, float bdinbu, float bdinbd) override {}
void setMDCTbandstepBends(bool invert, int step) override {}
void setMDCTpostshiftBends(int h_shift, float v_shift) override {}
void setMDCTwindowincrBends(int window_incr) override {}
void setMDCTBandReassignmentBends(int* order) override {}
void setBitrateSquishBends(float squish) override {}
void setThresholdBias(float bias) override {}
void setMDCTfeedback(float feedback) override {}

float* getPsychoanalThreshold() override {
return nullptr;
}
float* getPsychoanalEnergy() override {
return nullptr;
}
float* getMDCTpreBend() override {
return nullptr;
}
float* getMDCTpostBend() override {
return nullptr;
}
int getShortBlockStatus() override {
return 0;
}
protected:
bool init_encoder() override {
return true;
}
void deinit_encoder() override {}
int validate_bitrate(int bitrate) override {
return bitrate;
}
int validate_samplerate(int samplerate) override {
return samplerate;
}

bool bInitialized;
};

#endif //MAIM_OPUSCONTROLLER_H
14 changes: 10 additions & 4 deletions Source/GUIelements/EncoderBitrateSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ EncoderBitrateSection::EncoderBitrateSection (juce::AudioProcessorValueTreeState
: StageWindow(p),
psychoanalGraph(p),
biasSlider(p, "thresholdbias", "Tilt"),
encoderAttachment(p, "encoder", encoderButton),
encoderAttachment(p, "encoder", encoderSelection),
bitrateSlider(p, "bitrate", "Bitrate"),
squishSlider(p, "turbo", "Turbo")
{
Expand All @@ -26,7 +26,12 @@ EncoderBitrateSection::EncoderBitrateSection (juce::AudioProcessorValueTreeState

addAndMakeVisible(biasSlider);
addAndMakeVisible(psychoanalGraph);
addAndMakeVisible(encoderButton);
// addAndMakeVisible(encoderButton);
addAndMakeVisible(encoderSelection);
encoderSelection.addItem("blade", 1);
encoderSelection.addItem("lame", 2);
encoderSelection.addItem("opus", 3);

addAndMakeVisible(bitrateSlider);
addAndMakeVisible(squishSlider);
}
Expand Down Expand Up @@ -57,8 +62,9 @@ void EncoderBitrateSection::resized()
const auto leftPanel = usable_bounds.withRight(bitrateSlider.getX()).withTrimmedTop(10);
const auto rightPanel = usable_bounds.withLeft(bitrateSlider.getRight()).withTrimmedTop(10);

encoderButton.setBounds(leftPanel.withHeight(leftPanel.getHeight() * 0.4).withTrimmedLeft(10).withTrimmedRight(10));
squishSlider.setBounds(leftPanel.withTop(encoderButton.getBottom() + 10));
// encoderButton.setBounds(leftPanel.withHeight(leftPanel.getHeight() * 0.4).withTrimmedLeft(10).withTrimmedRight(10));
encoderSelection.setBounds(leftPanel.withHeight(leftPanel.getHeight() * 0.4).withTrimmedLeft(10).withTrimmedRight(10));
squishSlider.setBounds(leftPanel.withTop(encoderSelection.getBottom() + 10));

psychoanalGraph.setBounds(rightPanel.withHeight(leftPanel.getHeight() * 0.4).withTrimmedLeft(10).withTrimmedRight(10));
biasSlider.setBounds(rightPanel.withTop(psychoanalGraph.getBottom() + 10));
Expand Down
3 changes: 2 additions & 1 deletion Source/GUIelements/EncoderBitrateSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class EncoderBitrateSection : public StageWindow, public juce::ValueTree::Listen
NamedRotarySlider biasSlider;

juce::ToggleButton encoderButton {"Blade Encoder|Lame Encoder"};
const juce::AudioProcessorValueTreeState::ButtonAttachment encoderAttachment;
juce::ComboBox encoderSelection;
const juce::AudioProcessorValueTreeState::ComboBoxAttachment encoderAttachment;
NamedRotarySlider bitrateSlider;
NamedRotarySlider squishSlider;

Expand Down
53 changes: 44 additions & 9 deletions Source/MP3ControllerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,12 @@ void MP3ControllerManager::changeController(int bitrate, Encoder encoder)
if (encoder == lame) {
desiredEncoder = lame;
offController = &(lameControllers[offIndex]);
} else {
} else if (encoder == blade) {
desiredEncoder = blade;
offController = &(bladeControllers[offIndex]);
} else if (encoder == opus) {
desiredEncoder = opus;
offController = &(opusControllers[offIndex]);
}

offController->init(samplerate, samplesPerBlock, desiredBitrate);
Expand Down Expand Up @@ -304,12 +307,29 @@ void MP3ControllerManager::timerCallback()
float* threshold = getPsychoanalThreshold();

juce::var thresholdV, energyV;

for (int i = 0; i < 22; ++i) {
thresholdV.append(rescalePsychoanal(threshold[i]));
energyV.append(rescalePsychoanal(energy[i]));

if (energy) {
for (int i = 0; i < 22; ++i) {
energyV.append(rescalePsychoanal(energy[i]));
}
} else {
for (int i = 0; i < 22; ++i) {
energyV.append(0);
}

}


if (threshold) {
for (int i = 0; i < 22; ++i) {
thresholdV.append(rescalePsychoanal(threshold[i]));
}
} else {
for (int i = 0; i < 22; ++i) {
thresholdV.append(0);
}

}

auto psychoSpectrum = parameters.state.getChildWithName("psychoanal");
psychoSpectrum.setProperty("threshold", thresholdV, nullptr);
psychoSpectrum.setProperty("energy", energyV, nullptr);
Expand All @@ -319,10 +339,25 @@ void MP3ControllerManager::timerCallback()

juce::var preBendV, postBendV;

for (int i = 0; i < 576; ++i) {
preBendV.append(rescaleMDCT(preBend[i]));
postBendV.append(rescaleMDCT(postBend[i]));
if (preBend) {
for (int i = 0; i < 576; ++i) {
preBendV.append (rescaleMDCT (preBend[i]));
}
} else {
for (int i = 0; i < 576; ++i) {
preBendV.append (0);
}
}
if (postBend) {
for (int i = 0; i < 576; ++i) {
postBendV.append (rescaleMDCT (postBend[i]));
}
} else {
for (int i = 0; i < 576; ++i) {
postBendV.append (0);
}
}

auto mdctSamples = parameters.state.getChildWithName("mdct");
mdctSamples.setProperty("pre", preBendV, nullptr);
mdctSamples.setProperty("post",postBendV, nullptr);
Expand Down
Loading

0 comments on commit db8ec78

Please sign in to comment.