void GaussianDerivation::xyDerivation() { for(int x=-win_size; x<=win_size; x++) { for(int y=-win_size; y<=win_size; y++) { double c = -((x*y)/sigma4); m_xyDerviation[x + win_size][y + win_size] = c * arr[x + win_size][y + win_size]; } } normalizeData(m_xyDerviation,win_size); }
int main(int argc, char **argv) { uint16 * img = read_tiff((char*)"GMARBLES.tif"); uint16 * normalizedTiff = normalizeData(img); //uint16 * unnormalizedTiff = unNormalizeData(normalizedTiff); write_tiff((char*)"GMARBLESNORM.tif", normalizedTiff); //write_tiff_strip_file((char*)"Tritsmfin-s1051OUT.tif", unnormalizedTiff); //8 bit image //uint16 * img = read_tiff_strip_file((char*)"GMARBLES.TIF"); //uint16* normalizedImg = normalizeData(img); //unsigned short* unnormalizedImg = unNormalizeData(normalizedImg); //write_tiff_strip_file((char*)"Tritsmfin-s1051OUT.tif", img); return 0; }
enum decoder_command decoder_data(struct decoder *decoder, struct input_stream *is, const void *_data, size_t length, float data_time, uint16_t bitRate, struct replay_gain_info *replay_gain_info) { const char *data = _data; assert(dc.state == DECODE_STATE_DECODE); assert(length % audio_format_frame_size(&dc.in_audio_format) == 0); if (dc.command == DECODE_COMMAND_STOP || dc.command == DECODE_COMMAND_SEEK || length == 0) return dc.command; /* send stream tags */ if (update_stream_tag(decoder, is)) { enum decoder_command cmd; if (decoder->decoder_tag != NULL) { /* merge with tag from decoder plugin */ struct tag *tag; tag = tag_merge(decoder->stream_tag, decoder->decoder_tag); cmd = do_send_tag(decoder, is, tag); tag_free(tag); } else /* send only the stream tag */ cmd = do_send_tag(decoder, is, decoder->stream_tag); if (cmd != DECODE_COMMAND_NONE) return cmd; } if (!audio_format_equals(&dc.in_audio_format, &dc.out_audio_format)) { data = pcm_convert(&decoder->conv_state, &dc.in_audio_format, data, length, &dc.out_audio_format, &length); /* under certain circumstances, pcm_convert() may return an empty buffer - this condition should be investigated further, but for now, do this check as a workaround: */ if (data == NULL) return DECODE_COMMAND_NONE; } while (length > 0) { struct music_chunk *chunk; char *dest; size_t nbytes; bool full; chunk = decoder_get_chunk(decoder, is); if (chunk == NULL) { assert(dc.command != DECODE_COMMAND_NONE); return dc.command; } dest = music_chunk_write(chunk, &dc.out_audio_format, data_time, bitRate, &nbytes); if (dest == NULL) { /* the chunk is full, flush it */ decoder_flush_chunk(decoder); notify_signal(&pc.notify); continue; } assert(nbytes > 0); if (nbytes > length) nbytes = length; /* copy the buffer */ memcpy(dest, data, nbytes); /* apply replay gain or normalization */ if (replay_gain_info != NULL && replay_gain_mode != REPLAY_GAIN_OFF) replay_gain_apply(replay_gain_info, dest, nbytes, &dc.out_audio_format); else if (normalizationEnabled) normalizeData(dest, nbytes, &dc.out_audio_format); /* expand the music pipe chunk */ full = music_chunk_expand(chunk, &dc.out_audio_format, nbytes); if (full) { /* the chunk is full, flush it */ decoder_flush_chunk(decoder); notify_signal(&pc.notify); } data += nbytes; length -= nbytes; } return DECODE_COMMAND_NONE; }
int main(int argc, char* argv[]) { HumdrumFileSet infiles; majorKey = majorKeyBellman; minorKey = minorKeyBellman; // process the command-line options checkOptions(options, argc, argv); // figure out the number of input files to process int numinputs = options.getArgCount(); Array<double> absbeat; Array<int> pitch; Array<double> duration; Array<double> level; Array<double> distribution(12); Array<double> scores(24); string filename; Array<int> b40hist; int bestkey = 0; int i, j; if (numinputs < 1) { infiles.read(cin); } else { for (i=0; i<numinputs; i++) { infiles.readAppend(options.getArg(i+1)); } } for (i=0; i<infiles.getCount(); i++) { filename = infiles[i].getFilename(); if (continuousQ) { analyzeContinuously(infiles[i], windowsize, stepsize, majorKey, minorKey); continue; } infiles[i].getNoteArray(absbeat, pitch, duration, level); for (j=0; j<pitch.getSize(); j++) { pitch[j] = Convert::base40ToMidiNoteNumber(pitch[j]); } if (rawQ) { if (normalizeQ) { normalizeData(majorKey, 12); normalizeData(minorKey, 12); } bestkey = analyzeKeyRawCorrelation(scores.getBase(), distribution.getBase(), pitch.getBase(), duration.getBase(), pitch.getSize(), rhythmQ, majorKey, minorKey); } else if (euclideanQ) { equalizeData(majorKey, 12, 1.0); equalizeData(minorKey, 12, 1.0); bestkey = analyzeKeyEuclidean(scores.getBase(), distribution.getBase(), pitch.getBase(), duration.getBase(), pitch.getSize(), rhythmQ, majorKey, minorKey); } else { bestkey = analyzeKeyKS2(scores.getBase(), distribution.getBase(), pitch.getBase(), duration.getBase(), pitch.getSize(), rhythmQ, majorKey, minorKey); } getBase40Histogram(b40hist, infiles[i]); printAnalysis(bestkey, scores, distribution, filename, b40hist, infiles[i]); } return 0; }
int analyzeKeyRawCorrelation(double* scores, double* distribution, int* pitch, double* durations, int size, int rhythmQ, double* majorKey, double* minorKey) { int i, j; int histogram[12] = {0}; for (i=0; i<24; i++) { scores[i] = 0.0; } if (size == 0) { return -1; // return -1 if no data to analyze } for (i=0; i<12; i++) { distribution[i] = 0.0; } // generate a histogram of pitches for (i=0; i<size; i++) { histogram[pitch[i]%12]++; if (rhythmQ) { distribution[pitch[i]%12] += durations[i]/4.0; // dur in whole notes } else { distribution[pitch[i]%12] += 0.25; } } if (normalizeQ) { normalizeData(distribution, 12); } double maj_temp; double min_temp; int subscript; double* r_major = scores; double* r_minor = scores + 12; for (i=0; i<12; i++) { maj_temp = min_temp = 0; // Examine all pitches for each key, for (j=0; j<12; j++) { subscript = (i+j)%12; maj_temp += (majorKey[j] * distribution[subscript]); min_temp += (minorKey[j] * distribution[subscript]); } if (maj_temp <= 0.0) { r_major[i] = 0.0; } else { r_major[i] = maj_temp; } if (min_temp <= 0.0) { r_minor[i] = 0.0; } else { r_minor[i] = min_temp; } } // now figure out which key is the largest. int bestkey = 0; for (i=1; i<24; i++) { if (scores[i] > scores[bestkey]) { bestkey = i; } } return bestkey; }