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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
/*
* Test PortBurn
*
* Dominic Mazzoni
* License: LGPL
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#if defined(_WIN32)
#include <Windows.h>
#else
#include <unistd.h>
#endif
#include "portburn.h"
const char *filename = "clip.wav";
const int file_frames = 166;
const int frame_size = 588;
#define swap_uint16(x) \
((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
#define FailErr(result) \
if (result != 0) { \
printf("Failed: %d\n", result); \
goto end; \
}
int main(int argc, char **argv) {
FILE *fp;
short *buffer = (short *)malloc(file_frames * frame_size * 4);
void *handle = PortBurn_Open();
int count = PortBurn_GetNumDevices(handle);
int i, j;
unsigned int swaptest;
int needswap;
swaptest = 0x01020304;
if (((unsigned char *)&swaptest)[0] == 1) {
printf("Big-endian machine, will do byteswapping\n");
needswap = 1;
}
else {
printf("Little-endian machine, will not do byteswapping\n");
needswap = 0;
}
if (count == 0) {
printf("No devices found!\n");
goto end;
}
for(i = 0; i < count; i++) {
char *name = PortBurn_GetDeviceName(handle, i);
printf("Device %d: '%s'\n", i, name);
free(name);
}
printf("Using the first device\n");
FailErr(PortBurn_OpenDevice(handle, 0));
printf("Press enter when the device is ready\n");
getchar();
int state;
FailErr(PortBurn_GetMediaState(handle, &state));
if (!(state & pbMediaBlank)) {
printf("Media is not blank...erase? (y=erase, anything else aborts)\n");
if (getchar() != 'y') {
printf("aborting...\n");
goto end;
}
FailErr(PortBurn_StartErasing(handle, pbEraseQuick));
float complete;
while (PortBurn_GetEraseStatus(handle, &complete) == pbSuccess) {
if (complete == 1.0f) {
break;
}
#if defined(_WIN32)
// Sleep(1000);
#else
sleep(1);
#endif
}
}
printf("Staging audio\n");
#if defined(_WIN32)
FailErr(PortBurn_StartStaging(handle, "c:\temp"));
#else
FailErr(PortBurn_StartStaging(handle, "/tmp"));
#endif
fp = fopen(filename, "r");
if (!fp) {
printf("Couldn't open file: %s\n", filename);
goto end;
}
fseek(fp, 44, SEEK_SET);
fread(buffer, 2, file_frames * frame_size * 2, fp);
fclose(fp);
if (needswap) {
for(i = 0; i < file_frames * frame_size * 2; i++) {
((unsigned short *)buffer)[i] =
swap_uint16(((unsigned short *)buffer)[i]);
}
}
FailErr(PortBurn_StartTrack(handle, "80 loops"));
for(j = 0; j < 80; j++) {
for(i = 0; i < file_frames; i++) {
FailErr(PortBurn_AddFrame(handle, &buffer[i * 2 * frame_size]));
}
}
FailErr(PortBurn_EndTrack(handle));
FailErr(PortBurn_StartTrack(handle, "100 loops"));
for(j = 0; j < 100; j++) {
for(i = 0; i < file_frames; i++) {
FailErr(PortBurn_AddFrame(handle, &buffer[i * 2 * frame_size]));
}
}
FailErr(PortBurn_EndTrack(handle));
printf("Burning!!!\n");
FailErr(PortBurn_StartBurning(handle));
for(;;) {
float frac;
int result;
result = PortBurn_GetStatus(handle, &frac);
if (result != 0)
break;
printf("Status: %.3f\n", frac);
if (frac == 1.0f) {
printf("Completed!!!\n");
break;
}
#if defined(_WIN32)
Sleep(1000);
#else
sleep(1);
#endif
}
end:
printf("Cleaning up\n");
PortBurn_CloseDevice(handle);
if (handle) {
PortBurn_Close(handle);
}
printf("Press enter to end\n");
getchar();
return 0;
}
|