-
Notifications
You must be signed in to change notification settings - Fork 3
/
JUDASRAW.C
58 lines (53 loc) · 1.54 KB
/
JUDASRAW.C
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
/*
* JUDAS raw sample routines
*/
#include <stdlib.h>
#include <stdio.h>
#include <mem.h>
#include "judas.h"
SAMPLE *judas_loadrawsample(char *name, int repeat, int end, unsigned char voicemode);
SAMPLE *judas_loadrawsample(char *name, int repeat, int end, unsigned char voicemode)
{
int length;
int handle;
SAMPLE *smp;
/* Don't waste memory if Nosound */
judas_error = JUDAS_OK;
if (judas_device == DEV_NOSOUND)
{
return &fakesample;
}
judas_error = JUDAS_OPEN_ERROR;
handle = judas_open(name);
if (handle == -1) return NULL;
length = judas_seek(handle, 0, SEEK_END);
if (length == -1)
{
judas_close(handle);
return NULL;
}
judas_seek(handle, 0, SEEK_SET);
smp = judas_allocsample(length);
if (!smp)
{
judas_close(handle);
return NULL;
}
if (end == 0) end = length;
if (end > length) end = length;
if (repeat > length - 1) repeat = length - 1;
judas_error = JUDAS_READ_ERROR;
if (judas_read(handle, smp->start, length) != length)
{
judas_freesample(smp);
judas_close(handle);
return NULL;
}
judas_close(handle);
smp->repeat = smp->start + repeat;
smp->end = smp->start + end;
smp->voicemode = voicemode | VM_ON;
judas_ipcorrect(smp);
judas_error = JUDAS_OK;
return smp;
}