Skip to content

Commit c6582ab

Browse files
committed
adjust parameter names
1 parent 99887c3 commit c6582ab

File tree

4 files changed

+71
-72
lines changed

4 files changed

+71
-72
lines changed

README.md

Lines changed: 57 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This **library** provides a **synthetizer** for making music from samples (.wav
1010

1111

1212

13-
The Synthetizer take on one side the samples, and on the other side the Notes to play. Each Wav can be reused for multiple play.
13+
The Synthetizer takes on one side the samples, and on the other side the Notes to play. Each Wav can be reused for multiple play.
1414

1515

1616

@@ -34,17 +34,19 @@ The API now works on Windows and Linux (Rpi). A conditional compilation, dependi
3434

3535
Implementing your own file format reading is possible in populating the **SoundSample** type. Additional contribution can permit to handle more input file format.
3636

37-
#### Synthetizer capabilities
37+
#### Synthetizer capabilities
3838

39-
- 0.05 ms lattency for the moment, suitable for a lot of applications
39+
- Real Time Playing and Offline Playing
4040
- The max number of voice depends on the hardware provided, there is no hardcoded limitations, one can change the **MAX_VOICES** constant, and see whether it match the requierments. (As the number of polyphonie is increased, the processing may be heavier and can lead to increase the jitter and buffer sizes).
4141
- Parametrized volume for each playing sound.
4242
- Resampling : currently Nearest neighborhood algorithm (can be improved)
43+
- Variable Output frequency, permit to adjust CPU consumption
4344

4445
#### Current Drivers
4546

4647
- Win32 SoundDriver
47-
- Alsa SoundDriver
48+
- Alsa SoundDriver (*nix platforms)
49+
- PCM 16 bit Wav Output, using a cross plateform.
4850

4951

5052
Can be extended outside the library, depending on needs. Theses drivers show how to implement one.
@@ -58,62 +60,58 @@ Below, an example of the use of the synthetizer in 5 mins:
5860

5961

6062
```pascal
61-
procedure Test_Open_And_Play_A_Sample(T : in out Test_Case'Class) is
62-
63-
use Synth.Synthetizer;
64-
S : Synthetizer_Type;
65-
D : Synth.Driver.Sound_Driver_Access;
66-
Sample : Synth.SoundSample;
67-
Sample2 : Synth.SoundSample;
68-
V,V1 : Voice;
69-
begin
70-
71-
Put_Line("Load the Sound Driver, from WIN32/Linux driver");
72-
Synth.Driver.Open (Driver => D);
73-
74-
Put_Line("Open the synth");
75-
Open (D => D, S => S);
76-
77-
Put_Line("Load the sample test.wav");
78-
79-
Synth.Wav.Load ("test-files/test.wav", Sample);
80-
Synth.Wav.Load ("test-files/test.wav", Sample2);
81-
82-
Sample.Note_Frequency := 440.0; -- the sample is a A, 440 Hz
83-
84-
Put_Line("Play Sound");
85-
Play(Synt => S,
86-
S => Sample,
87-
Frequency => 440.0,
88-
Channel => 1,
89-
Opened_Voice => V1);
63+
64+
with Synth.Driver;
65+
with Synth.Wav;
66+
67+
with Synth;use Synth;
68+
with Synth.Synthetizer;use Synth.Synthetizer;
69+
70+
with Ada.Text_IO;use Ada.Text_IO;
71+
72+
73+
procedure Test_Play is
74+
Device : Driver.Sound_Driver_Access;
75+
Sample : SoundSample;
76+
S : Synthetizer_Type;
77+
V : Voice;
78+
79+
begin
80+
81+
-- Default Driver, opening, using the
82+
-- default 44100 Khz output
83+
Synth.Driver.Open (Device);
84+
85+
Put_Line("Load wav");
86+
Synth.Wav.Load(FileName => "test-files/test.wav",
87+
Sample => Sample);
9088
91-
-- wait a bit to ear the 1st sound
92-
delay 0.5;
89+
Sample.Note_Frequency := MIDICode_To_Frequency(65);
90+
Sample.Cant_Stop := false;
9391
94-
Sample2.Note_Frequency := 440.0;
95-
Put_Line("Play Sound");
92+
Put_Line("Open synth");
93+
94+
Open(Driver_Access => Device,
95+
Synt => S);
96+
97+
Put_Line("Play sound " & Integer'Image(Sample.Mono_Data'Length));
98+
99+
for I in 0..10 loop
96100
Play(Synt => S,
97-
S => Sample2,
98-
Frequency => 880.0, -- play the second sample at a +1 Octave
99-
Channel => 1,
101+
S => Sample,
102+
Frequency => MIDICode_To_Frequency(65 + I),
100103
Opened_Voice => V);
101-
Put_Line("Stop the Voice :" & Voice'Image(V1));
102-
103-
-- stop the 1st sample, given the Opened Voice
104-
Stop(Synt => S, Opened_Voice => V1);
104+
delay(0.3);
105+
Stop(S, V);
106+
end loop;
105107
106-
-- wait to ear the 2nd sample
107-
delay 2.0;
108+
delay(3.0);
108109
110+
Close(Synt => S);
109111
110-
S.Close;
111112
112-
exception
113-
when E : others =>
114-
Synth.DumpException(E);
113+
end;
115114
116-
end;
117115
```
118116

119117

@@ -122,8 +120,6 @@ Below, an example of the use of the synthetizer in 5 mins:
122120

123121
The synthetizer behave nicely, there are no large amount or synchro between components. Playing Midi file is really amazing, and the quality for a first shot is quite interessing, be can be improved.
124122

125-
CPU consumption is not large, but on typical computer, process priority has to be upgraded to populate the sound buffer.
126-
127123

128124

129125
## Next actions
@@ -133,21 +129,22 @@ Version 0.1:
133129
- ~~Fix Memory Leak for Win32 driver~~
134130
- ~~Eval portaudio for output rendering (X Plateform sound toolkit)~~
135131
- ~~Add Alsa Driver for linux plateforms~~
136-
- Add Wav Driver for debugging purpose or to disk exports
137-
- Interfaçing with C, Java for consuming the library
132+
- ~~Add Wav Driver for debugging purpose or to disk exports~~
133+
- Ahead of time playin
138134

139135
Version 0.2:
140136

141-
- Improving Sound quality, add filters
137+
- Improving Sound quality, add numeric filters, and additional effects
138+
- Digital Signal processing : Permit to have Low / High Bandwidth filters, Compressors, Volume regulation, FadeIn / FadeOut
139+
- Lattency detection, permitting to have both online and offline playin
140+
141+
Mid Term Version :
142142

143-
Version 0.3:
143+
- Interfaçing with C, Java for consuming the library
144144

145145
- Porting to Spark, remove the task part for embedded usage
146146

147-
148147

149148
### Areas That can be covered next (if time permit)
150149

151-
Digital Signal processing : Permit to have Low / High Bandwidth filters, Compressors, Volume regulation, FadeIn / FadeOut
152-
153150
FM generators : The current buffers are filled with Wav samples, but a short abstraction can be done to introduce signal generators and modulators to extends the use to "analog like" synthetizers.

src/synth-synthetizer.adb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ package body Synth.Synthetizer is
2828
----------
2929

3030
procedure Open
31-
(D : Driver.Sound_Driver_Access;
32-
S : out Synthetizer_Type;
31+
(Driver_Access : Driver.Sound_Driver_Access;
32+
Synt : out Synthetizer_Type;
3333
Buffer_Size : Natural := Natural (0.05 * 44_100.0 / 2.0);
3434
Buffers_Number : Positive := 1)
3535
is
3636
begin
3737

3838
-- human perceived sound within 0.05 s
3939

40-
S := new Synthetizer_Structure_Type;
41-
S.Init (D => D,
40+
Synt := new Synthetizer_Structure_Type;
41+
Synt.Init (D => Driver_Access,
4242
NBBuffer => Buffers_Number,
4343
Buffer_Length => Buffer_Size);
4444

@@ -51,9 +51,9 @@ package body Synth.Synthetizer is
5151
-- Close --
5252
-----------
5353

54-
procedure Close (S : in out Synthetizer_Type) is
54+
procedure Close (Synt : in out Synthetizer_Type) is
5555
begin
56-
S.Close;
56+
Synt.Close;
5757
exception
5858
when E : others =>
5959
DumpException (E);
@@ -306,7 +306,7 @@ package body Synth.Synthetizer is
306306
* 1_000_000.0 / Long_Float (Task_Driver_Frequency)));
307307

308308
-- must be late in the pipeline,
309-
-- TODO: change it
309+
-- TODO: improve it
310310
Last_Clock := Clock - 10 * Task_Buffer_Number * Time_Jitter; -- attention
311311

312312
Init_Clock := Last_Clock;
@@ -746,12 +746,12 @@ package body Synth.Synthetizer is
746746
function "/"(f : Play_Second; f2 : Float) return Play_Second is
747747
begin
748748
return f / Play_Second (f2);
749-
end;
749+
end "/";
750750

751751
function "*"(f : Play_Second; f2 : Float) return Play_Second is
752752
begin
753753
return f * Play_Second (f2);
754-
end;
754+
end "*";
755755

756756
-- forward
757757
procedure Internal_Process_Buffer (VSA : Voice_Structure_Type;

src/synth-synthetizer.ads

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ package Synth.Synthetizer is
6969

7070
-- open the synth device
7171
procedure Open
72-
(D : Driver.Sound_Driver_Access;
73-
S : out Synthetizer_Type;
72+
(Driver_Access : Driver.Sound_Driver_Access;
73+
Synt : out Synthetizer_Type;
7474
Buffer_Size : Natural := Natural (0.05 * 44_100.0 / 2.0);
7575
Buffers_Number : Positive := 1);
7676

7777
-- close the synth
78-
procedure Close (S : in out Synthetizer_Type);
78+
procedure Close (Synt : in out Synthetizer_Type);
7979

8080
----------
8181
-- Play --

src/synth.ads

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ package Synth is
4646

4747
Mono_Data : Frame_Array_Access;
4848

49+
-- if can't stop is true, the sound will be played
50+
-- until the end (can't be stopped)
4951
Cant_Stop : Boolean;
5052

5153
case HasLoop is

0 commit comments

Comments
 (0)