Skip to content

Commit

Permalink
Adds test for embedding of wav files
Browse files Browse the repository at this point in the history
  • Loading branch information
modlfo committed Jun 19, 2017
1 parent 1413d4d commit db88c66
Show file tree
Hide file tree
Showing 9 changed files with 426 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/passes/pass2.ml
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ module EmbedWavFile = struct
|> Array.to_list


(** Verifies that the arguments of the attribute correspond to the necessary *)
let checkInputVariables (loc:Loc.t) (args:typed_id list) : exp * exp =
match args with
| [ channel ; index ] -> MakeTables.getInputVar channel, MakeTables.getInputVar index
Expand All @@ -259,7 +260,8 @@ module EmbedWavFile = struct
Error.raiseError msg loc


let accessChannel fname (attr:attr) (channel:exp) (index:exp) (samples:int) (i:int) : stmt =
(** Generates the statement that reads the arrays if the reuqested channel matches *)
let accessChannel (fname:id) (attr:attr) (channel:exp) (index:exp) (samples:int) (i:int) : stmt =
let attr_bool = { emptyAttr with typ = Some(VType.Constants.bool_type) } in
let attr_real = { emptyAttr with typ = Some(VType.Constants.real_type) } in
let attr_int = { emptyAttr with typ = Some(VType.Constants.int_type) } in
Expand All @@ -274,6 +276,7 @@ module EmbedWavFile = struct
attr)


(** Generates the function that access the data of the wave file *)
let makeNewBody (fname:id) (attr:attr) (args:typed_id list) (wave:WavFile.wave) : stmt =
let attr_real = { emptyAttr with typ = Some(VType.Constants.real_type) } in
let channel, index = checkInputVariables attr.loc args in
Expand All @@ -282,6 +285,7 @@ module EmbedWavFile = struct
StmtBlock(None, stmts @ [default], attr)


(** Generates a function <name>_samples that return the size of the wav file *)
let makeSizeFunction (fname:id) (attr:attr) (size:int) : stmt =
let attr_int = { emptyAttr with typ = Some(VType.Constants.int_type) } in
let size_name = appendToId fname "_samples" in
Expand Down
93 changes: 93 additions & 0 deletions test/code/wav_file.cpp.fixed.base
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@

/* Code automatically generated by Vult https://github.com/modlfo/vult */
#include "wav_file.h"

int Wav_file_ext_wave_samples(){return 600;}

fix16_t Wav_file_ext_wave(int channel, int index){
if(channel == 0){ return fix_get(fix_wrap_array(Wav_file_ext_wave_chan_0),(index % 600)); }
return 0x0 /* 0.000000 */;
}

void Wav_file__ctx_type_2_init(Wav_file__ctx_type_2 &_output_){
Wav_file__ctx_type_2 _ctx;
_ctx.i = 0;
_output_ = _ctx;
return ;
}

void Wav_file_index_init(Wav_file__ctx_type_2 &_output_){
Wav_file__ctx_type_2_init(_output_);
return ;
}

int Wav_file_index(Wav_file__ctx_type_2 &_ctx){
_ctx.i = ((_ctx.i + 1) % Wav_file_ext_wave_samples());
return _ctx.i;
}

void Wav_file__ctx_type_3_init(Wav_file__ctx_type_3 &_output_){
Wav_file__ctx_type_3 _ctx;
Wav_file__ctx_type_2_init(_ctx._inst2);
_output_ = _ctx;
return ;
}

void Wav_file_osc_wave_init(Wav_file__ctx_type_3 &_output_){
Wav_file__ctx_type_3_init(_output_);
return ;
}

fix16_t Wav_file_osc_wave(Wav_file__ctx_type_3 &_ctx, fix16_t cv){
return Wav_file_ext_wave(0,Wav_file_index(_ctx._inst2));
}

void Wav_file__ctx_type_4_init(Wav_file__ctx_type_4 &_output_){
Wav_file__ctx_type_4 _ctx;
Wav_file__ctx_type_3_init(_ctx._inst4);
_output_ = _ctx;
return ;
}

void Wav_file_process_init(Wav_file__ctx_type_4 &_output_){
Wav_file__ctx_type_4_init(_output_);
return ;
}

fix16_t Wav_file_process(Wav_file__ctx_type_4 &_ctx, fix16_t cv){
return Wav_file_osc_wave(_ctx._inst4,cv);
}

void Wav_file_noteOn_init(Wav_file__ctx_type_4 &_output_){
Wav_file__ctx_type_4_init(_output_);
return ;
}

void Wav_file_noteOn(Wav_file__ctx_type_4 &_ctx, int note, int velocity, int channel){
}

void Wav_file_noteOff_init(Wav_file__ctx_type_4 &_output_){
Wav_file__ctx_type_4_init(_output_);
return ;
}

void Wav_file_noteOff(Wav_file__ctx_type_4 &_ctx, int note, int channel){
}

void Wav_file_controlChange_init(Wav_file__ctx_type_4 &_output_){
Wav_file__ctx_type_4_init(_output_);
return ;
}

void Wav_file_controlChange(Wav_file__ctx_type_4 &_ctx, int control, int value, int channel){
}

void Wav_file_default_init(Wav_file__ctx_type_4 &_output_){
Wav_file__ctx_type_4_init(_output_);
return ;
}

void Wav_file_default(Wav_file__ctx_type_4 &_ctx){
}


93 changes: 93 additions & 0 deletions test/code/wav_file.cpp.float.base
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@

/* Code automatically generated by Vult https://github.com/modlfo/vult */
#include "wav_file.h"

int Wav_file_ext_wave_samples(){return 600;}

float Wav_file_ext_wave(int channel, int index){
if(channel == 0){ return float_get(float_wrap_array(Wav_file_ext_wave_chan_0),(index % 600)); }
return 0.000000f;
}

void Wav_file__ctx_type_2_init(Wav_file__ctx_type_2 &_output_){
Wav_file__ctx_type_2 _ctx;
_ctx.i = 0;
_output_ = _ctx;
return ;
}

void Wav_file_index_init(Wav_file__ctx_type_2 &_output_){
Wav_file__ctx_type_2_init(_output_);
return ;
}

int Wav_file_index(Wav_file__ctx_type_2 &_ctx){
_ctx.i = ((_ctx.i + 1) % Wav_file_ext_wave_samples());
return _ctx.i;
}

void Wav_file__ctx_type_3_init(Wav_file__ctx_type_3 &_output_){
Wav_file__ctx_type_3 _ctx;
Wav_file__ctx_type_2_init(_ctx._inst2);
_output_ = _ctx;
return ;
}

void Wav_file_osc_wave_init(Wav_file__ctx_type_3 &_output_){
Wav_file__ctx_type_3_init(_output_);
return ;
}

float Wav_file_osc_wave(Wav_file__ctx_type_3 &_ctx, float cv){
return Wav_file_ext_wave(0,Wav_file_index(_ctx._inst2));
}

void Wav_file__ctx_type_4_init(Wav_file__ctx_type_4 &_output_){
Wav_file__ctx_type_4 _ctx;
Wav_file__ctx_type_3_init(_ctx._inst4);
_output_ = _ctx;
return ;
}

void Wav_file_process_init(Wav_file__ctx_type_4 &_output_){
Wav_file__ctx_type_4_init(_output_);
return ;
}

float Wav_file_process(Wav_file__ctx_type_4 &_ctx, float cv){
return Wav_file_osc_wave(_ctx._inst4,cv);
}

void Wav_file_noteOn_init(Wav_file__ctx_type_4 &_output_){
Wav_file__ctx_type_4_init(_output_);
return ;
}

void Wav_file_noteOn(Wav_file__ctx_type_4 &_ctx, int note, int velocity, int channel){
}

void Wav_file_noteOff_init(Wav_file__ctx_type_4 &_output_){
Wav_file__ctx_type_4_init(_output_);
return ;
}

void Wav_file_noteOff(Wav_file__ctx_type_4 &_ctx, int note, int channel){
}

void Wav_file_controlChange_init(Wav_file__ctx_type_4 &_output_){
Wav_file__ctx_type_4_init(_output_);
return ;
}

void Wav_file_controlChange(Wav_file__ctx_type_4 &_ctx, int control, int value, int channel){
}

void Wav_file_default_init(Wav_file__ctx_type_4 &_output_){
Wav_file__ctx_type_4_init(_output_);
return ;
}

void Wav_file_default(Wav_file__ctx_type_4 &_ctx){
}


Loading

0 comments on commit db88c66

Please sign in to comment.