Skip to content

Commit

Permalink
Merge branch 'master' of github.com:iplayfast/arduino-scope
Browse files Browse the repository at this point in the history
Conflicts:
	CMakeLists.txt
	main.cpp
  • Loading branch information
iplayfast committed Jun 24, 2011
2 parents 0c50416 + e2676a0 commit 62f11c8
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 117 deletions.
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ cmake_minimum_required(VERSION 2.8)

project(scope)

ADD_DEFINITIONS (-D WITH_SOUND)
#target_link_libraries(main ${EXTRA_LIBS})

#target_link_libraries(scope X11 GL GLU)
add_executable(scope main.cpp TFuzzy.c ${EXTRA_LIBS})
set(EXTRA_LIBS line sound)
add_library(line line.cpp)
add_library(sound sound.cpp)
add_executable(scope main.cpp TFuzzy.c ${EXTRA_LIBS})
include_directories(/usr/include/pulse)



target_link_libraries(${PROJECT_NAME} X11 m pulse-simple GL GLU glut)
17 changes: 17 additions & 0 deletions line.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "line.h"


line::line() { for (int i=0; i< CHANNELNUM; i++) {visible[i] = true; scale[i] = 1;}; end = 0; }
void line::AddSample(int* val) { timemark[end]=*val++; for (int i=0; i< CHANNELNUM; i++){ value[i][end] = *val++; }; end++; if (end==TRACELENGTH) end--; }
int line::GetChSample(int start, int ch) const { if (start<0) start=0; if (start>=end) return 0; else return value[ch][start] / scale[ch]; }
int line::GetTime(int start) { return timemark[start]; }
void line::IncScale(int ch) { if (scale[ch]>1) scale[ch]--; }
void line::DecScale(int ch) { if (scale[ch]<512) scale[ch]++; }
bool line::IsVisible(int ch) const { return visible[ch]; }
void line::ToggleVisible(int ch) { visible[ch] = !visible[ch]; }
int line::GetScale(int ch) const { return scale[ch]; }
void line::Reset() { end=0; }
int line::GetBaseTime() const { return timemark[0]; }
int line::GetMaxTime() const { if (end>0) return timemark[end-1]; else return timemark[0]; }
int line::GetEnd() const { return end; }

32 changes: 32 additions & 0 deletions line.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef LINES_H
#define LINES_H

#define TRACELENGTH 10000
#define CHANNELNUM 2


class line
{
int timemark[TRACELENGTH];
int value[CHANNELNUM][TRACELENGTH];
int end;
bool visible[CHANNELNUM];
int scale[CHANNELNUM];

public:
line();
void AddSample(int* val);
int GetChSample(int start, int ch) const;
int GetTime(int start);
void IncScale(int ch);
void DecScale(int ch);
bool IsVisible(int ch) const;
void ToggleVisible(int ch);
int GetScale(int ch) const;
void Reset();
int GetBaseTime() const;
int GetMaxTime() const;
int GetEnd() const;
};

#endif
123 changes: 8 additions & 115 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

#define WITH_SOUND

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
Expand All @@ -18,21 +16,20 @@ using namespace Crystal;
using namespace Fuzzy;
#ifdef WITH_SOUND
/* includes needed for sound */
#include "sound.h"
#endif

#include <sys/ioctl.h>
#include <sys/fcntl.h>
#include <sys/soundcard.h>
#include <unistd.h>
#include <simple.h>

#define RIFF 1179011410 /* little endian value for ASCII-encoded 'RIFF' */
#define WAVE 1163280727 /* little endian value for ASCII-encoded 'WAVE' */
#define FMT 544501094 /* little endian value for ASCII-encoded 'fmt' */
#define DATA 1635017060 /* little endian value for ASCII-encoded 'data' */
#include "line.h"


FILE *usb;
int width=640;
int height = 480;

/*
#define TRACELENGTH 10000
#define CHANNELNUM 2
class line
Expand Down Expand Up @@ -71,11 +68,12 @@ class line
int GetMaxTime() const { if (end>0) return timemark[end-1]; else return timemark[0]; }
int GetEnd() const { return end; }
};

*/
line lines;
char buff[100]="";
int buffcount=0;
bool help = false; // shows help screen if true

void UpdateSamples()
{

Expand Down Expand Up @@ -104,31 +102,6 @@ void ResetSamples()
lines.Reset();
}

typedef struct {
unsigned int chunkID; /* ASCII: 'RIFF' */
unsigned int chunkSize; /* filelength - 8 */
unsigned int format; /* ASCII: 'WAVE' */

unsigned int subChunk1ID; /* ASCII: 'fmt ' */
unsigned int subChunk1Size; /* length of sub chunk, 16 for PCM*/
unsigned short int audioFormat; /* should be 1 for PCM */
unsigned short int numberOfChannels; /* 1 Mono, 2 Stereo */
unsigned int sampleRate; /* sample frequency */
unsigned int byteRate; /* sampleRate * numberOfChannels * bitsPerSample/8 */

unsigned short int blockAlign; /* numberOfChannels * bitsPerSample/8 */
unsigned short int bitsPerSample; /* 8, 16 bit */

unsigned int subChunk2ID; /* ASCII: 'data' */
unsigned int subChunk2Size; /* size of the sample data */
} waveHeader;

typedef struct {
waveHeader* header;
unsigned char* sampleData;
} waveFile;
#endif

/* stuff about our window grouped together */
typedef struct {
Display *dpy;
Expand Down Expand Up @@ -289,86 +262,6 @@ int loadBmp(const char* filename, textureImage* texture)
return 1;
}

#ifdef WITH_SOUND
int loadWave(const char* filename, waveFile* waveFile)
{
FILE* file;
/* allocate space for the wave header */
waveFile->header = (waveHeader *) malloc(sizeof(waveHeader));
/* make sure the file is there and open it read-only (binary) */
if ((file = fopen(filename, "rb")) == NULL) {
printf("File not found : %s\n", filename);
return 0;
}
/* read the wave header */
if (!fread(waveFile->header, sizeof(waveHeader), 1, file)) {
printf("Error reading file!\n");
return 0;
}
/* check if it is a riff wave file */
if (waveFile->header->chunkID != RIFF ||
waveFile->header->format != WAVE ||
waveFile->header->subChunk1ID != FMT ||
waveFile->header->subChunk2ID != DATA) {
printf("Soundfile %s not in wave format!\n", filename);
return 0;
}
/* we can only handle uncompressed, PCM encoded waves! */
if (waveFile->header->audioFormat != 1) {
printf("Soundfile not PCM encoded!\n");
return 0;
}
/* we can only handle up to two channels (stereo) */
if (waveFile->header->numberOfChannels > 2) {
printf("Soundfile has more than 2 channels!\n");
return 0;
}
waveFile->sampleData = (unsigned char *) malloc(waveFile->header->subChunk2Size);
fseek(file, sizeof(waveHeader), SEEK_SET);
if (!fread(waveFile->sampleData, waveFile->header->subChunk2Size, 1,
file)) {
printf("Error loading file!\n");
return 0;
}
return 1;
}
pa_simple *s;
void playSound(waveFile* sound) {
int error;
pa_simple_write (s,
sound->sampleData,
sound->header->subChunk2Size,
&error);
}
void killsound()
{
pa_simple_free(s);
}
// printf("%d %d\n",x,70 + lines[0].GetSample(x));

int initSound(int bitsPerSample, int numberOfChannels, int samplingRate)
{
pa_sample_spec ss;

ss.format = PA_SAMPLE_S16NE;
ss.channels = 2;
ss.rate = 44100;

s = pa_simple_new(NULL, // Use the default server.
"Fooapp", // Our application's name.
PA_STREAM_PLAYBACK,
NULL, // Use the default device.
"Music", // Description of our stream.
&ss, // Our sample format.
NULL, // Use default channel map
NULL, // Use default buffering attributes.
NULL // Ignore error code.
);


return 0;
}
#endif

/* Load Bitmaps And Convert To Textures */
Bool loadGLTextures()
Expand Down
104 changes: 104 additions & 0 deletions sound.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#ifdef WITH_SOUND
#include "sound.h"

int loadWave(const char* filename, waveFile* waveFile)
{
FILE* file;
/* allocate space for the wave header */
waveFile->header = (waveHeader *) malloc(sizeof(waveHeader));
/* make sure the file is there and open it read-only (binary) */
if ((file = fopen(filename, "rb")) == NULL) {
printf("File not found : %s\n", filename);
return 0;
}
/* read the wave header */
if (!fread(waveFile->header, sizeof(waveHeader), 1, file)) {
printf("Error reading file!\n");
return 0;
}
/* check if it is a riff wave file */
if (waveFile->header->chunkID != RIFF ||
waveFile->header->format != WAVE ||
waveFile->header->subChunk1ID != FMT ||
waveFile->header->subChunk2ID != DATA) {
printf("Soundfile %s not in wave format!\n", filename);
return 0;
}
/* we can only handle uncompressed, PCM encoded waves! */
if (waveFile->header->audioFormat != 1) {
printf("Soundfile not PCM encoded!\n");
return 0;
}
/* we can only handle up to two channels (stereo) */
if (waveFile->header->numberOfChannels > 2) {
printf("Soundfile has more than 2 channels!\n");
return 0;
}
waveFile->sampleData = (unsigned char *) malloc(waveFile->header->subChunk2Size);
fseek(file, sizeof(waveHeader), SEEK_SET);
if (!fread(waveFile->sampleData, waveFile->header->subChunk2Size, 1,
file)) {
printf("Error loading file!\n");
return 0;
}
return 1;
}

pa_simple *s;

void playSound(waveFile* sound) {
int error;
pa_simple_write (s,
sound->sampleData,
sound->header->subChunk2Size,
&error);
}

void killsound()
{
pa_simple_free(s);
}
// printf("%d %d\n",x,70 + lines[0].GetSample(x));

int initSound(int bitsPerSample, int numberOfChannels, int samplingRate)
{
pa_sample_spec ss;

ss.format = PA_SAMPLE_S16NE;
ss.channels = 2;
ss.rate = 44100;

s = pa_simple_new(NULL, // Use the default server.
"Fooapp", // Our application's name.
PA_STREAM_PLAYBACK,
NULL, // Use the default device.
"Music", // Description of our stream.
&ss, // Our sample format.
NULL, // Use default channel map
NULL, // Use default buffering attributes.
NULL // Ignore error code.
);


return 0;
}





#else

int loadWave(const char* filename, waveFile* waveFile)
{
return 1;
};

void playSound(waveFile* sound) {};
void killsound() {};
int initSound(int bitsPerSample, int numberOfChannels, int samplingRate)
{
return 0;
};

#endif
44 changes: 44 additions & 0 deletions sound.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifdef WITH_SOUND

#include <stdio.h>
#include <stdlib.h>

#include <sys/soundcard.h>
#include <simple.h>
#define RIFF 1179011410 /* little endian value for ASCII-encoded 'RIFF' */
#define WAVE 1163280727 /* little endian value for ASCII-encoded 'WAVE' */
#define FMT 544501094 /* little endian value for ASCII-encoded 'fmt' */
#define DATA 1635017060 /* little endian value for ASCII-encoded 'data' */

#endif

typedef struct {
unsigned int chunkID; /* ASCII: 'RIFF' */
unsigned int chunkSize; /* filelength - 8 */
unsigned int format; /* ASCII: 'WAVE' */

unsigned int subChunk1ID; /* ASCII: 'fmt ' */
unsigned int subChunk1Size; /* length of sub chunk, 16 for PCM*/
unsigned short int audioFormat; /* should be 1 for PCM */
unsigned short int numberOfChannels; /* 1 Mono, 2 Stereo */
unsigned int sampleRate; /* sample frequency */
unsigned int byteRate; /* sampleRate * numberOfChannels * bitsPerSample/8 */

unsigned short int blockAlign; /* numberOfChannels * bitsPerSample/8 */
unsigned short int bitsPerSample; /* 8, 16 bit */

unsigned int subChunk2ID; /* ASCII: 'data' */
unsigned int subChunk2Size; /* size of the sample data */
} waveHeader;

typedef struct {
waveHeader* header;
unsigned char* sampleData;
} waveFile;


int loadWave(const char* filename, waveFile* waveFile);
void playSound(waveFile* sound);
void killsound();
int initSound(int bitsPerSample, int numberOfChannels, int samplingRate);

0 comments on commit 62f11c8

Please sign in to comment.