svn merge -r 14236:14505 https://svn.blender.org/svnroot/bf-blender/trunk/blender
[blender.git] / intern / SoundSystem / SND_test / SND_test.c
1 /*  SND_test.c   nov 2000
2 *  
3 *  testfile for the SND module
4
5 * janco verduin
6 *
7 * $Id$
8  *
9  * ***** BEGIN GPL LICENSE BLOCK *****
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  *
25  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
26  * All rights reserved.
27  *
28  * The Original Code is: all of this file.
29  *
30  * Contributor(s): none yet.
31  *
32  * ***** END GPL LICENSE BLOCK *****
33 */
34
35 #include "SND_C-api.h"
36 #include "BlenderWaveCacheCApi.h"
37 #include "OpenALC-Api.h"
38 #include <stdio.h>
39 #include <stdlib.h>
40
41 #ifdef HAVE_CONFIG_H
42 #include <config.h>
43 #endif
44
45 #if defined(WIN32)
46 #include <io.h>
47 #else
48 #include <unistd.h>
49 #endif
50 #include <fcntl.h>
51
52 static int buf[3];
53
54 float oPos[3]={3.0, 0.0,-1.0};
55 float oVel[3]={0.0, 0.0, 1.0};
56 float oOri[6]={0.0, 0.0, 1.0, 0.0, 1.0, 0.0};
57
58 void* ReadFile(char *filename)
59 {
60         int file, filelen;
61         void *data = NULL;
62
63 #if defined(WIN32)      
64         file = open(filename, O_BINARY|O_RDONLY);
65 #else
66         file = open(filename, 0|O_RDONLY);
67 #endif
68
69         if (file == -1) {
70                 printf("can't open file.\n");
71                 printf("press q for quit.\n");
72
73         }
74         else {
75                 filelen = lseek(file, 0, SEEK_END);
76                 lseek(file, 0, SEEK_SET);
77                 
78                 if (filelen != 0){
79                         data = malloc(filelen);
80                         if (read(file, data, filelen) != filelen) {
81                                 free(data);
82                                 data = NULL;
83                         }
84                 }
85                 close(file);
86                 
87         }
88         return (data);
89 }
90
91 int main(int argc, char* argv[])
92 {
93         int ch;
94         char* samplename = NULL;
95         void* sampleinmemory = NULL;
96         SND_CacheHandle wavecache = NULL;
97         SND_SceneHandle scene = NULL;
98         SND_ObjectHandle object = NULL;
99         
100         wavecache = SND_GetWaveCache();
101         scene = SND_CreateOpenALScene(wavecache);
102
103         samplename = "2.wav";
104         sampleinmemory = ReadFile(samplename);
105         
106         if (sampleinmemory) {
107
108                 object = SND_CreateObject();
109                 SND_AddMemoryLocation(samplename, sampleinmemory);
110                 SND_SetSampleName(object, samplename);
111                 SND_AddObject(scene, object);
112                 printf("go your gang...\n");
113                 printf("1: play\n");
114                 printf("2: stop\n");
115                 printf("q: quit\n");
116         }
117         do
118         {
119                 ch = getchar();
120                 ch = toupper(ch);
121                 switch (ch)
122                 {
123                 case '1':
124                         {
125                                 SND_SetPitch(object, 1.0);
126                                 SND_SetGain(object, 1.0);
127                                 SND_StartSound(object);
128                                 break;
129                         }
130                 case '2':
131                         {
132                                 SND_StopSound(object);
133                                 break;
134                         }
135                 default:
136                         break;
137                 }
138
139                 SND_Proceed(scene);
140
141         } while (ch != 'Q');
142         
143         if (object) {
144                 
145                 SND_RemoveObject(scene, object);
146                 SND_DeleteObject(object);
147         }
148         
149         SND_DeleteScene(scene);
150         SND_DeleteCache();
151         
152         return 0;
153         
154 }