/[svn]/web/trunk/www.linuxsampler.org/libgig/examples/dlswritedemo.cpp
ViewVC logotype

Contents of /web/trunk/www.linuxsampler.org/libgig/examples/dlswritedemo.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1405 - (show annotations) (download)
Fri Oct 12 11:45:58 2007 UTC (16 years, 6 months ago) by schoenebeck
File size: 3669 byte(s)
* moved libgig home from
  http://stud.hs-heilbronn.de/~cschoene/projects/libgig/
  to the linuxsampler site, that is:
  http://www.linuxsampler.org/libgig/

1 // This little test application demonstrates how to create and modify DLS
2 // files with libgig 3.0.0.
3 //
4 // Date: 2006-04-29
5 //
6 // Compile with: 'g++ -lgig -o dlswritedemo dlswritedemo.cpp'
7
8 #include <DLS.h>
9
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <string.h>
13
14 int main() {
15 // four stupid little sample "waves"
16 // (each having three sample points length, 16 bit depth, mono)
17 int16_t sampleData1[] = { 1, 2, 3 };
18 int16_t sampleData2[] = { 4, 5, 6 };
19 int16_t sampleData3[] = { 7, 8, 9 };
20 int16_t sampleData4[] = { 10,11,12 };
21 try {
22 // create an empty DLS file
23 DLS::File file;
24 // we give it an internal name, not mandatory though
25 file.pInfo->Name = "Foo DLS File";
26
27 // create four samples
28 DLS::Sample* pSample1 = file.AddSample();
29 DLS::Sample* pSample2 = file.AddSample();
30 DLS::Sample* pSample3 = file.AddSample();
31 DLS::Sample* pSample4 = file.AddSample();
32 // give those samples a name (not mandatory)
33 pSample1->pInfo->Name = "Foo Sample 1";
34 pSample2->pInfo->Name = "Foo Sample 2";
35 pSample3->pInfo->Name = "Foo Sample 3";
36 pSample4->pInfo->Name = "Foo Sample 4";
37 // set meta informations for those samples
38 pSample1->Channels = 1; // mono
39 pSample1->BitDepth = 16; // 16 bits
40 pSample1->FrameSize = 16/*bitdepth*/ / 8/*1 byte are 8 bits*/ * 1/*mono*/;
41 pSample1->SamplesPerSecond = 44100;
42 pSample2->Channels = 1; // mono
43 pSample2->BitDepth = 16; // 16 bits
44 pSample2->FrameSize = 16 / 8 * 1;
45 pSample2->SamplesPerSecond = 44100;
46 pSample3->Channels = 1; // mono
47 pSample3->BitDepth = 16; // 16 bits
48 pSample3->FrameSize = 16 / 8 * 1;
49 pSample3->SamplesPerSecond = 44100;
50 pSample4->Channels = 1; // mono
51 pSample4->BitDepth = 16; // 16 bits
52 pSample4->FrameSize = 16 / 8 * 1;
53 pSample4->SamplesPerSecond = 44100;
54 // resize those samples to a length of three sample points
55 // (again: _sample_points_ NOT bytes!)
56 pSample1->Resize(3);
57 pSample2->Resize(3);
58 pSample3->Resize(3);
59 pSample4->Resize(3);
60 // retrieve a buffer in RAM to place the sample's wave forms there
61 void* pData = pSample1->LoadSampleData();
62 memccpy(pData, sampleData1, 3, 2);
63 pData = pSample2->LoadSampleData();
64 memccpy(pData, sampleData2, 3, 2);
65 pData = pSample3->LoadSampleData();
66 memccpy(pData, sampleData3, 3, 2);
67 pData = pSample4->LoadSampleData();
68 memccpy(pData, sampleData4, 3, 2);
69
70 // create four instruments
71 DLS::Instrument* pInstrument1 = file.AddInstrument();
72 DLS::Instrument* pInstrument2 = file.AddInstrument();
73 DLS::Instrument* pInstrument3 = file.AddInstrument();
74 DLS::Instrument* pInstrument4 = file.AddInstrument();
75 // give them a name (not mandatory)
76 pInstrument1->pInfo->Name = "Foo Instrument 1";
77 pInstrument2->pInfo->Name = "Foo Instrument 2";
78 pInstrument3->pInfo->Name = "Foo Instrument 3";
79 pInstrument4->pInfo->Name = "Foo Instrument 4";
80 // create a region for all instruments and apply a sample to the
81 // regions
82 pInstrument1->AddRegion()->SetSample(pSample1);
83 pInstrument2->AddRegion()->SetSample(pSample2);
84 pInstrument3->AddRegion()->SetSample(pSample3);
85 pInstrument4->AddRegion()->SetSample(pSample4);
86
87 // save file as of now
88 file.Save("foo.dls");
89 } catch (RIFF::Exception e) {
90 e.PrintMessage();
91 return -1;
92 }
93 return 0;
94 }

  ViewVC Help
Powered by ViewVC