mirror of
https://gitlab.com/then-try-this/samplebrain.git
synced 2025-05-12 10:37:20 +00:00
windows loading fix and streaming debug
This commit is contained in:
parent
1b73a28f5b
commit
f94db030b5
@ -315,8 +315,8 @@ ios &spiralcore::operator||(ios &s, sample &sa) {
|
|||||||
ofstream *pos=dynamic_cast<ofstream*>(&s);
|
ofstream *pos=dynamic_cast<ofstream*>(&s);
|
||||||
if (pos!=NULL) {
|
if (pos!=NULL) {
|
||||||
ofstream &os = *pos;
|
ofstream &os = *pos;
|
||||||
size_t len = sa.m_length;
|
u64 len = sa.m_length;
|
||||||
os.write((char*)&len,sizeof(size_t));
|
os.write((char*)&len,sizeof(u64));
|
||||||
os.write((char*)sa.m_data,sa.m_length*sizeof(audio_type));
|
os.write((char*)sa.m_data,sa.m_length*sizeof(audio_type));
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
@ -325,8 +325,8 @@ ios &spiralcore::operator||(ios &s, sample &sa) {
|
|||||||
ifstream *pis=dynamic_cast<ifstream*>(&s);
|
ifstream *pis=dynamic_cast<ifstream*>(&s);
|
||||||
assert(pis!=NULL);
|
assert(pis!=NULL);
|
||||||
ifstream &is = *pis;
|
ifstream &is = *pis;
|
||||||
size_t len=0;
|
u64 len=0;
|
||||||
is.read((char *)&len,sizeof(size_t));
|
is.read((char *)&len,sizeof(u64));
|
||||||
float *data = new float[len];
|
float *data = new float[len];
|
||||||
is.read((char*)data,len*sizeof(audio_type));
|
is.read((char*)data,len*sizeof(audio_type));
|
||||||
sa.m_data = data;
|
sa.m_data = data;
|
||||||
|
@ -25,85 +25,38 @@ using namespace std;
|
|||||||
template<>ios &spiralcore::operator||(ios &s, string &v) {
|
template<>ios &spiralcore::operator||(ios &s, string &v) {
|
||||||
ofstream *pos=dynamic_cast<ofstream*>(&s);
|
ofstream *pos=dynamic_cast<ofstream*>(&s);
|
||||||
if (pos!=NULL) {
|
if (pos!=NULL) {
|
||||||
ofstream &os = *pos;
|
#ifdef DEBUG_STREAM
|
||||||
u64 len = v.length();
|
cerr<<"streaming out string "<<v<<endl;
|
||||||
os.write((char *)&len,sizeof(u64));
|
#endif
|
||||||
os.write((char*)(v.c_str()),v.length());
|
ofstream &os = *pos;
|
||||||
return os;
|
u64 len = v.length();
|
||||||
}
|
os.write((char *)&len,sizeof(u64));
|
||||||
else
|
os.write((char*)(v.c_str()),v.length());
|
||||||
{
|
return os;
|
||||||
ifstream *pis=dynamic_cast<ifstream*>(&s);
|
} else {
|
||||||
assert(pis!=NULL);
|
ifstream *pis=dynamic_cast<ifstream*>(&s);
|
||||||
ifstream &is = *pis;
|
assert(pis!=NULL);
|
||||||
u64 len=0;
|
ifstream &is = *pis;
|
||||||
is.read((char *)&len,sizeof(u64));
|
u64 len=0;
|
||||||
if (len>0) {
|
is.read((char *)&len,sizeof(u64));
|
||||||
char *str = new char[len+1];
|
if (len>0) {
|
||||||
is.read(str,len);
|
char *str = new char[len+1];
|
||||||
str[len]='\0';
|
is.read(str,len);
|
||||||
v = string(str);
|
str[len]='\0';
|
||||||
delete[] str;
|
v = string(str);
|
||||||
}
|
delete[] str;
|
||||||
else {
|
} else {
|
||||||
//v=string("");
|
//v=string("");
|
||||||
}
|
}
|
||||||
return is;
|
|
||||||
|
#ifdef DEBUG_STREAM
|
||||||
|
cerr<<"streamed in string "<<v<<endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return is;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*ios &operator||(ios &s, vector<U> &v) {
|
|
||||||
ofstream *pos=dynamic_cast<ofstream*>(&s);
|
|
||||||
if (pos!=NULL) {
|
|
||||||
ofstream &os = *pos;
|
|
||||||
size_t len = v.length();
|
|
||||||
os.write((char *)&len,sizeof(size_t));
|
|
||||||
return os.write((char*)(&v[0]),v.length()*sizeof(U));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ifstream *pis=dynamic_cast<ifstream*>(&s);
|
|
||||||
assert(pis);
|
|
||||||
ifstream &is = *pis;
|
|
||||||
size_t len=0;
|
|
||||||
is.read((char *)&len,sizeof(size_t));
|
|
||||||
v.reserve(len);
|
|
||||||
is.read((char*)&v[0],len);
|
|
||||||
return is;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}*/
|
|
||||||
/*
|
|
||||||
template<class U>ios &operator||(ios &s, vector<U> &v) {
|
|
||||||
ofstream *pos=dynamic_cast<ofstream*>(&s);
|
|
||||||
if (pos!=NULL) {
|
|
||||||
ofstream &os = *pos;
|
|
||||||
size_t len = v.length();
|
|
||||||
for (size_t i=0; i<len; ++i) {
|
|
||||||
os||v[i];
|
|
||||||
}
|
|
||||||
return os;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ifstream *pis=dynamic_cast<ifstream*>(&s);
|
|
||||||
assert(pis);
|
|
||||||
ifstream &is = *pis;
|
|
||||||
size_t len=0;
|
|
||||||
is.read((char *)&len,sizeof(size_t));
|
|
||||||
v.reserve(len);
|
|
||||||
for (size_t i=0; i<len; ++i) {
|
|
||||||
is||v[i];
|
|
||||||
}
|
|
||||||
return is;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
void spiralcore::stream_unit_test() {
|
void spiralcore::stream_unit_test() {
|
||||||
|
|
||||||
ofstream of("test_data/streamtest.bin",ios::binary);
|
ofstream of("test_data/streamtest.bin",ios::binary);
|
||||||
|
@ -20,15 +20,27 @@
|
|||||||
#include <list>
|
#include <list>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
//#define DEBUG_STREAM
|
||||||
|
|
||||||
|
#ifdef DEBUG_STREAM
|
||||||
|
#include <typeinfo>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace spiralcore {
|
namespace spiralcore {
|
||||||
|
|
||||||
// hack to do both stream directions in one function
|
// hack to do both stream directions in one function
|
||||||
// saw this years ago at computer artworks, not seen it since...
|
// saw this years ago at computer artworks, not seen it since...
|
||||||
|
|
||||||
template<typename T>std::ios &operator||(std::ios &s, T &v) {
|
template<typename T>std::ios &operator||(std::ios &s, T &v) {
|
||||||
|
|
||||||
|
#ifdef DEBUG_STREAM
|
||||||
|
std::cerr<<"streaming a "<<typeid(v).name()<<std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
std::ofstream *pos=dynamic_cast<std::ofstream*>(&s);
|
std::ofstream *pos=dynamic_cast<std::ofstream*>(&s);
|
||||||
if (pos!=NULL) {
|
if (pos!=NULL) {
|
||||||
std::ofstream &os = *pos;
|
std::ofstream &os = *pos;
|
||||||
@ -47,34 +59,18 @@ template<typename T>std::ios &operator||(std::ios &s, T &v) {
|
|||||||
|
|
||||||
template<>std::ios &operator||(std::ios &s, std::string &v);
|
template<>std::ios &operator||(std::ios &s, std::string &v);
|
||||||
|
|
||||||
/*
|
|
||||||
template<typename T, typename U>T *stream_array(std::ios &s, T *v, U &len) {
|
|
||||||
std::ofstream *pos=dynamic_cast<std::ofstream*>(&s);
|
|
||||||
if (pos!=NULL) {
|
|
||||||
std::ofstream &os = *pos;
|
|
||||||
os||len;
|
|
||||||
os.write((char*)v,sizeof(T)*len);
|
|
||||||
return v;
|
|
||||||
} else {
|
|
||||||
std::ifstream *pis=dynamic_cast<std::ifstream*>(&s);
|
|
||||||
assert(pis);
|
|
||||||
std::ifstream &is = *pis;
|
|
||||||
is||len;
|
|
||||||
if (v!=NULL) delete[] v;
|
|
||||||
T* t = new T[len];
|
|
||||||
is.read((char *)t,sizeof(T)*len);
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
template<typename T>std::ios &stream_vector(std::ios &s, std::vector<T> &v) {
|
template<typename T>std::ios &stream_vector(std::ios &s, std::vector<T> &v) {
|
||||||
std::ofstream *pos=dynamic_cast<std::ofstream*>(&s);
|
std::ofstream *pos=dynamic_cast<std::ofstream*>(&s);
|
||||||
|
|
||||||
|
#ifdef DEBUG_STREAM
|
||||||
|
std::cerr<<"streaming a vector "<<std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (pos!=NULL) {
|
if (pos!=NULL) {
|
||||||
std::ofstream &os = *pos;
|
std::ofstream &os = *pos;
|
||||||
size_t len = v.size();
|
u64 len = v.size();
|
||||||
os||len;
|
os||len;
|
||||||
for (size_t i=0; i<len; ++i) {
|
for (u64 i=0; i<len; ++i) {
|
||||||
os||v[i];
|
os||v[i];
|
||||||
}
|
}
|
||||||
return os;
|
return os;
|
||||||
@ -84,11 +80,11 @@ template<typename T>std::ios &stream_vector(std::ios &s, std::vector<T> &v) {
|
|||||||
std::ifstream *pis=dynamic_cast<std::ifstream*>(&s);
|
std::ifstream *pis=dynamic_cast<std::ifstream*>(&s);
|
||||||
assert(pis);
|
assert(pis);
|
||||||
std::ifstream &is = *pis;
|
std::ifstream &is = *pis;
|
||||||
size_t len=0;
|
u64 len=0;
|
||||||
is||len;
|
is||len;
|
||||||
//v.reserve(len);
|
//v.reserve(len);
|
||||||
v.clear();
|
v.clear();
|
||||||
for (size_t i=0; i<len; ++i) {
|
for (u64 i=0; i<len; ++i) {
|
||||||
T t;
|
T t;
|
||||||
is||t;
|
is||t;
|
||||||
v.push_back(t);
|
v.push_back(t);
|
||||||
@ -99,9 +95,12 @@ template<typename T>std::ios &stream_vector(std::ios &s, std::vector<T> &v) {
|
|||||||
|
|
||||||
// skip a vector when loading
|
// skip a vector when loading
|
||||||
template<typename T>std::ios &skip_vector(std::ifstream &is) {
|
template<typename T>std::ios &skip_vector(std::ifstream &is) {
|
||||||
size_t len=0;
|
#ifdef DEBUG_STREAM
|
||||||
|
std::cerr<<"skipping a vector"<<std::endl;
|
||||||
|
#endif
|
||||||
|
u64 len=0;
|
||||||
is||len;
|
is||len;
|
||||||
for (size_t i=0; i<len; ++i) {
|
for (u64 i=0; i<len; ++i) {
|
||||||
T t;
|
T t;
|
||||||
is||t;
|
is||t;
|
||||||
}
|
}
|
||||||
@ -111,9 +110,12 @@ template<typename T>std::ios &skip_vector(std::ifstream &is) {
|
|||||||
|
|
||||||
template<typename T>std::ios &stream_list(std::ios &s, std::list<T> &v) {
|
template<typename T>std::ios &stream_list(std::ios &s, std::list<T> &v) {
|
||||||
std::ofstream *pos=dynamic_cast<std::ofstream*>(&s);
|
std::ofstream *pos=dynamic_cast<std::ofstream*>(&s);
|
||||||
|
#ifdef DEBUG_STREAM
|
||||||
|
std::cerr<<"streaming a list"<<std::endl;
|
||||||
|
#endif
|
||||||
if (pos!=NULL) {
|
if (pos!=NULL) {
|
||||||
std::ofstream &os = *pos;
|
std::ofstream &os = *pos;
|
||||||
size_t len = v.size();
|
u64 len = v.size();
|
||||||
os||len;
|
os||len;
|
||||||
for (typename std::list<T>::iterator i=v.begin(); i!=v.end(); ++i) {
|
for (typename std::list<T>::iterator i=v.begin(); i!=v.end(); ++i) {
|
||||||
os||*i;
|
os||*i;
|
||||||
@ -125,9 +127,9 @@ template<typename T>std::ios &stream_list(std::ios &s, std::list<T> &v) {
|
|||||||
std::ifstream *pis=dynamic_cast<std::ifstream*>(&s);
|
std::ifstream *pis=dynamic_cast<std::ifstream*>(&s);
|
||||||
assert(pis);
|
assert(pis);
|
||||||
std::ifstream &is = *pis;
|
std::ifstream &is = *pis;
|
||||||
size_t len=0;
|
u64 len=0;
|
||||||
is||len;
|
is||len;
|
||||||
for (size_t i=0; i<len; ++i) {
|
for (u64 i=0; i<len; ++i) {
|
||||||
T t;
|
T t;
|
||||||
is||t;
|
is||t;
|
||||||
v.push_back(t);
|
v.push_back(t);
|
||||||
@ -137,9 +139,12 @@ template<typename T>std::ios &stream_list(std::ios &s, std::list<T> &v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>std::ios &skip_list(std::istream &is) {
|
template<typename T>std::ios &skip_list(std::istream &is) {
|
||||||
size_t len=0;
|
#ifdef DEBUG_STREAM
|
||||||
|
std::cerr<<"skipping a list"<<std::endl;
|
||||||
|
#endif
|
||||||
|
u64 len=0;
|
||||||
is||len;
|
is||len;
|
||||||
for (size_t i=0; i<len; ++i) {
|
for (u64 i=0; i<len; ++i) {
|
||||||
T t;
|
T t;
|
||||||
is||t;
|
is||t;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user