summaryrefslogtreecommitdiffstats
path: root/noatun/modules/artseffects/extrastereo_impl.cc
blob: 3dc927057bef60dd9758f235f57c475fa3876428 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include "artsgui.h"
#include "artseffects.h"
#include "stdsynthmodule.h"
#include <dynamicrequest.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <convert.h>
#include "debug.h"
#include <connect.h>
#include <cstdlib>

using namespace Arts;

class ExtraStereo_impl : virtual public ExtraStereo_skel,
						 virtual public StdSynthModule
{
	float _intensity;
//	StereoEffectGUI mStereoEffectGUI;
public:
	float intensity() { return _intensity; }
	void intensity(float newValue) {
		_intensity = newValue;
//		cout << " **** INTENSITY = " << newValue << endl;
	}

	ExtraStereo_impl() : _intensity(2.0)
	{
//		mStereoEffectGUI = DynamicCast(server.createObject("Arts::ExtraStereo"));
//		DynamicRequest(mStereoEffectGUI).method("_set_effect").param(*this).invoke();

	}
	void calculateBlock(unsigned long samples)
	{
		unsigned long i;

		for(i = 0; i < samples; i++)
		{
			float average = (inleft[i] + inright[i]) / 2.0;

			float outleftnew = average + (inleft[i] - average) * _intensity;
			if(outleftnew > 1.0) outleft[i] = 1.0;
			else if(outleftnew < -1.0) outleft[i] = -1.0;
			else outleft[i] = outleftnew;

			float outrightnew = average + (inright[i] - average) * _intensity;
			if(outrightnew > 1.0) outright[i] = 1.0;
			else if(outrightnew < -1.0) outright[i] = -1.0;
			else outright[i] = outrightnew;
		}
	}
};


class VoiceRemoval_impl : virtual public VoiceRemoval_skel,
						 virtual public StdSynthModule
{
public:

	VoiceRemoval_impl()
	{

	}
	// This is based on the work of Anders Carlsson <[email protected]>
	void calculateBlock(unsigned long samples)
	{
		for (unsigned i = 0; i < samples; i++)
		{
			float outleftnew=inleft[i]-inright[i];
			float outrightnew=inright[i]-inleft[i];

			if (inleft[i] < -1.0) outleftnew = -1.0;
			else if (inleft[i] > 1.0) outleftnew = 1.0;

			if (inright[i] < -1.0) outrightnew = -1.0;
			else if (inright[i] > 1.0) outrightnew = 1.0;
			outleft[i] = outleftnew;
			outright[i] = outrightnew;
		}
		
	}
};

class RawWriter_impl : virtual public RawWriter_skel,
                          virtual public StdSynthModule
{
	int mFd;
public:
	RawWriter_impl()
	{
		std::string file=getenv("HOME");
		file.append("/arts-write.raw");
		mFd=::open(file.c_str(), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
	}
	~RawWriter_impl()
	{
		::close(mFd);
	}
	// This is based on the work of Anders Carlsson <[email protected]>
	void calculateBlock(unsigned long samples)
	{
		for (unsigned i = 0; i < samples; i++)
		{
			outleft[i]=inleft[i];
			outright[i]=inright[i];
		}
		unsigned char *buffer=new unsigned char[samples*4];
		convert_stereo_2float_i16le(samples,
									inleft, inright, buffer);
		::write(mFd, (const void*)buffer, samples*4);
		delete [] buffer;
	}
};

class ExtraStereoGuiFactory_impl : public ExtraStereoGuiFactory_skel
{
public:
	Widget createGui(Object object)
	{
		arts_return_val_if_fail(!object.isNull(), Arts::Widget::null());

		ExtraStereo e = DynamicCast(object);
		arts_return_val_if_fail(!e.isNull(), Arts::Widget::null());

		HBox hbox;
		hbox.width(80);
		hbox.height(80);
		hbox.show();


		Poti intense;
		intense.caption("Intensity");
		intense.color("red");
		intense.min(0);
		intense.max(5);
		intense.value(e.intensity());
		intense.parent(hbox);
		intense.show();
		connect(intense,"value_changed", e, "intensity");
		
		hbox._addChild(intense,"intensityWidget");
		
		return hbox;
	}
};


REGISTER_IMPLEMENTATION(ExtraStereo_impl);
REGISTER_IMPLEMENTATION(VoiceRemoval_impl);
REGISTER_IMPLEMENTATION(RawWriter_impl);
REGISTER_IMPLEMENTATION(ExtraStereoGuiFactory_impl);