576 |
int bitdepth; |
int bitdepth; |
577 |
switch (info.format & 0xff) { |
switch (info.format & 0xff) { |
578 |
case SF_FORMAT_PCM_S8: |
case SF_FORMAT_PCM_S8: |
|
bitdepth = 16; // we simply convert to 16 bit for now |
|
|
break; |
|
579 |
case SF_FORMAT_PCM_16: |
case SF_FORMAT_PCM_16: |
580 |
|
case SF_FORMAT_PCM_U8: |
581 |
bitdepth = 16; |
bitdepth = 16; |
582 |
break; |
break; |
583 |
case SF_FORMAT_PCM_24: |
case SF_FORMAT_PCM_24: |
|
bitdepth = 32; // we simply convert to 32 bit for now |
|
|
break; |
|
584 |
case SF_FORMAT_PCM_32: |
case SF_FORMAT_PCM_32: |
|
bitdepth = 32; |
|
|
break; |
|
|
case SF_FORMAT_PCM_U8: |
|
|
bitdepth = 16; // we simply convert to 16 bit for now |
|
|
break; |
|
585 |
case SF_FORMAT_FLOAT: |
case SF_FORMAT_FLOAT: |
|
bitdepth = 32; |
|
|
break; |
|
586 |
case SF_FORMAT_DOUBLE: |
case SF_FORMAT_DOUBLE: |
587 |
bitdepth = 32; // I guess we will always truncate this to 32 bit |
bitdepth = 24; |
588 |
break; |
break; |
589 |
default: |
default: |
590 |
sf_close(hFile); // close sound file |
sf_close(hFile); // close sound file |
591 |
throw std::string("format not supported"); // unsupported subformat (yet?) |
throw std::string("format not supported"); // unsupported subformat (yet?) |
592 |
} |
} |
593 |
// allocate appropriate copy buffer (TODO: for now we copy |
|
594 |
// it in one piece, might be tough for very long samples) |
const int bufsize = 10000; |
|
// and copy sample data into buffer |
|
|
int8_t* buffer = NULL; |
|
595 |
switch (bitdepth) { |
switch (bitdepth) { |
596 |
case 16: |
case 16: { |
597 |
buffer = new int8_t[2 * info.channels * info.frames]; |
short* buffer = new short[bufsize * info.channels]; |
598 |
// libsndfile does the conversion for us (if needed) |
sf_count_t cnt = info.frames; |
599 |
sf_readf_short(hFile, (short*) buffer, info.frames); |
while (cnt) { |
600 |
|
// libsndfile does the conversion for us (if needed) |
601 |
|
int n = sf_readf_short(hFile, buffer, bufsize); |
602 |
|
// write from buffer directly (physically) into .gig file |
603 |
|
iter->gig_sample->Write(buffer, n); |
604 |
|
cnt -= n; |
605 |
|
} |
606 |
|
delete[] buffer; |
607 |
break; |
break; |
608 |
case 32: |
} |
609 |
buffer = new int8_t[4 * info.channels * info.frames]; |
case 24: { |
610 |
// libsndfile does the conversion for us (if needed) |
int* srcbuf = new int[bufsize * info.channels]; |
611 |
sf_readf_int(hFile, (int*) buffer, info.frames); |
uint8_t* dstbuf = new uint8_t[bufsize * 3 * info.channels]; |
612 |
|
sf_count_t cnt = info.frames; |
613 |
|
while (cnt) { |
614 |
|
// libsndfile returns 32 bits, convert to 24 |
615 |
|
int n = sf_readf_int(hFile, srcbuf, bufsize); |
616 |
|
int j = 0; |
617 |
|
for (int i = 0 ; i < n * info.channels ; i++) { |
618 |
|
dstbuf[j++] = srcbuf[i] >> 8; |
619 |
|
dstbuf[j++] = srcbuf[i] >> 16; |
620 |
|
dstbuf[j++] = srcbuf[i] >> 24; |
621 |
|
} |
622 |
|
// write from buffer directly (physically) into .gig file |
623 |
|
iter->gig_sample->Write(dstbuf, n); |
624 |
|
cnt -= n; |
625 |
|
} |
626 |
|
delete[] srcbuf; |
627 |
|
delete[] dstbuf; |
628 |
break; |
break; |
629 |
|
} |
630 |
} |
} |
|
// write from buffer directly (physically) into .gig file |
|
|
(*iter).gig_sample->Write(buffer, info.frames); |
|
631 |
// cleanup |
// cleanup |
632 |
sf_close(hFile); |
sf_close(hFile); |
|
delete[] buffer; |
|
633 |
// on success we remove the sample from the import queue, |
// on success we remove the sample from the import queue, |
634 |
// otherwise keep it, maybe it works the next time ? |
// otherwise keep it, maybe it works the next time ? |
635 |
std::list<SampleImportItem>::iterator cur = iter; |
std::list<SampleImportItem>::iterator cur = iter; |
1082 |
int bitdepth; |
int bitdepth; |
1083 |
switch (info.format & 0xff) { |
switch (info.format & 0xff) { |
1084 |
case SF_FORMAT_PCM_S8: |
case SF_FORMAT_PCM_S8: |
|
bitdepth = 16; // we simply convert to 16 bit for now |
|
|
break; |
|
1085 |
case SF_FORMAT_PCM_16: |
case SF_FORMAT_PCM_16: |
1086 |
|
case SF_FORMAT_PCM_U8: |
1087 |
bitdepth = 16; |
bitdepth = 16; |
1088 |
break; |
break; |
1089 |
case SF_FORMAT_PCM_24: |
case SF_FORMAT_PCM_24: |
|
bitdepth = 32; // we simply convert to 32 bit for now |
|
|
break; |
|
1090 |
case SF_FORMAT_PCM_32: |
case SF_FORMAT_PCM_32: |
|
bitdepth = 32; |
|
|
break; |
|
|
case SF_FORMAT_PCM_U8: |
|
|
bitdepth = 16; // we simply convert to 16 bit for now |
|
|
break; |
|
1091 |
case SF_FORMAT_FLOAT: |
case SF_FORMAT_FLOAT: |
|
bitdepth = 32; |
|
|
break; |
|
1092 |
case SF_FORMAT_DOUBLE: |
case SF_FORMAT_DOUBLE: |
1093 |
bitdepth = 32; // I guess we will always truncate this to 32 bit |
bitdepth = 24; |
1094 |
break; |
break; |
1095 |
default: |
default: |
1096 |
sf_close(hFile); // close sound file |
sf_close(hFile); // close sound file |
1112 |
sample->BitDepth = bitdepth; |
sample->BitDepth = bitdepth; |
1113 |
sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels; |
sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels; |
1114 |
sample->SamplesPerSecond = info.samplerate; |
sample->SamplesPerSecond = info.samplerate; |
1115 |
|
sample->AverageBytesPerSecond = sample->FrameSize * sample->SamplesPerSecond; |
1116 |
|
sample->BlockAlign = sample->FrameSize; |
1117 |
|
sample->SamplesTotal = info.frames; |
1118 |
|
|
1119 |
|
SF_INSTRUMENT instrument; |
1120 |
|
if (sf_command(hFile, SFC_GET_INSTRUMENT, |
1121 |
|
&instrument, sizeof(instrument)) != SF_FALSE) |
1122 |
|
{ |
1123 |
|
sample->MIDIUnityNote = instrument.basenote; |
1124 |
|
|
1125 |
|
if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) { |
1126 |
|
sample->Loops = 1; |
1127 |
|
|
1128 |
|
switch (instrument.loops[0].mode) { |
1129 |
|
case SF_LOOP_FORWARD: |
1130 |
|
sample->LoopType = gig::loop_type_normal; |
1131 |
|
break; |
1132 |
|
case SF_LOOP_BACKWARD: |
1133 |
|
sample->LoopType = gig::loop_type_backward; |
1134 |
|
break; |
1135 |
|
case SF_LOOP_ALTERNATING: |
1136 |
|
sample->LoopType = gig::loop_type_bidirectional; |
1137 |
|
break; |
1138 |
|
} |
1139 |
|
sample->LoopStart = instrument.loops[0].start; |
1140 |
|
sample->LoopEnd = instrument.loops[0].end; |
1141 |
|
sample->LoopPlayCount = instrument.loops[0].count; |
1142 |
|
sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1; |
1143 |
|
} |
1144 |
|
} |
1145 |
|
|
1146 |
// schedule resizing the sample (which will be done |
// schedule resizing the sample (which will be done |
1147 |
// physically when File::Save() is called) |
// physically when File::Save() is called) |
1148 |
sample->Resize(info.frames); |
sample->Resize(info.frames); |
1260 |
const Glib::RefPtr<Gdk::DragContext>& context, int, int, |
const Glib::RefPtr<Gdk::DragContext>& context, int, int, |
1261 |
const Gtk::SelectionData& selection_data, guint, guint time) |
const Gtk::SelectionData& selection_data, guint, guint time) |
1262 |
{ |
{ |
|
gig::DimensionRegion* dimregion = m_DimRegionChooser.get_dimregion(); |
|
1263 |
gig::Sample* sample = *((gig::Sample**) selection_data.get_data()); |
gig::Sample* sample = *((gig::Sample**) selection_data.get_data()); |
1264 |
|
|
1265 |
if (sample && dimregion && selection_data.get_length() == sizeof(gig::Sample*)) { |
if (sample && selection_data.get_length() == sizeof(gig::Sample*)) { |
1266 |
if (sample != dimregion->pSample) { |
if (dimreg_edit.set_sample(sample)) { |
|
dimregion->pSample = sample; |
|
|
dimreg_edit.wSample->set_text(dimregion->pSample->pInfo->Name.c_str()); |
|
1267 |
std::cout << "Drop received sample \"" << |
std::cout << "Drop received sample \"" << |
1268 |
dimregion->pSample->pInfo->Name.c_str() << "\"" << std::endl; |
sample->pInfo->Name << "\"" << std::endl; |
1269 |
// drop success |
// drop success |
1270 |
context->drop_reply(true, time); |
context->drop_reply(true, time); |
|
file_changed(); |
|
1271 |
return; |
return; |
1272 |
} |
} |
1273 |
} |
} |