void spectrum_extension::disable() { b_active = false; list_vis.remove_item(this); static_api_ptr_t<play_callback_manager>()->unregister_callback(this); if (static_api_ptr_t<play_control>()->is_playing()) g_deregister_stream(this); if (!list_vis.get_count()) g_stream.release(); p_host.release(); }
void spectrum_extension::refresh(const audio_chunk * p_chunk) { ui_extension::visualisation_host::painter_ptr ps; p_host->create_painter(ps); HDC dc = ps->get_device_context(); const RECT * rc_client = ps->get_area(); { paint_background(dc, rc_client); if (g_is_stream_active(this) && p_chunk) { if (!br_foreground) br_foreground = CreateSolidBrush(cr_fore); if (mode == MODE_BARS) { unsigned totalbars = rc_client->right / m_bar_width; if (totalbars) { const audio_sample * p_data = p_chunk->get_data(); t_size sample_count = p_chunk->get_sample_count(); t_size channel_count = p_chunk->get_channels(); t_size i; for(i=0;i<totalbars;i++) { double val = 0; t_size starti, endi, j; g_scale_value(sample_count, i, totalbars, starti, endi, m_scale == scale_logarithmic); for (j=starti;j<=endi; j++) { if (j < sample_count) { double sample_val = 0; t_size k; for (k=0; k<channel_count; k++) sample_val += p_data[j*channel_count + k]; sample_val *= 1.0 / channel_count; val = max(val, sample_val); } } RECT r; r.left = 1 + i*m_bar_width; r.right = r.left + m_bar_width - m_bar_gap; r.bottom = rc_client->bottom ? rc_client->bottom-1 : 0; r.top = rc_client->bottom - g_scale_value_single(val, (rc_client->bottom + 1)/2 , m_vertical_scale == scale_logarithmic)*2; if (r.bottom>r.top) FillRect(dc,&r,br_foreground); } int j; for (j=rc_client->bottom; j>rc_client->top; j-=2) { RECT rc = {0, j-1, rc_client->right, j}; FillRect(dc,&rc,br_background); } } } else { const audio_sample * p_data = p_chunk->get_data(); t_size sample_count = p_chunk->get_sample_count(); t_size channel_count = p_chunk->get_channels(); t_size i; for(i=0;i<(t_size)rc_client->right;i++) { double val = 0; t_size starti, endi, j; g_scale_value(sample_count, i, rc_client->right, starti, endi, m_scale == scale_logarithmic); for (j=starti;j<=endi; j++) { if (j < sample_count) { double sample_val = 0; t_size k; for (k = 0; k<channel_count; k++) sample_val += p_data[j*channel_count + k]; sample_val *= 1.0 / channel_count; val = max(val, sample_val); } } RECT r; r.left = i; r.right = i+1; r.bottom = rc_client->bottom; r.top = rc_client->bottom - g_scale_value_single (val, rc_client->bottom, m_vertical_scale == scale_logarithmic); if (r.bottom>r.top) FillRect(dc,&r,br_foreground); } } } } ps.release(); }
void spectrum_extension::refresh(const audio_chunk * p_chunk) { ui_extension::visualisation_host::painter_ptr ps; p_host->create_painter(ps); HDC dc = ps->get_device_context(); const RECT * rc_client = ps->get_area(); { /* if (!br_background) br_background = CreateSolidBrush(cr_back); FillRect(dc,&rc_client,br_background);*/ paint_background(dc, rc_client); //HPEN pn = CreatePen(PS_SOLID, 1, cr_fore); //HPEN pn_old = SelectPen(dc, pn); if (g_is_stream_active(this) && p_chunk) { if (!br_foreground) br_foreground = CreateSolidBrush(cr_fore); if (mode == MODE_BARS) { unsigned totalbars = rc_client->right / m_bar_width; if (totalbars) { #if 1 const audio_sample * p_data = p_chunk->get_data(); t_size sample_count = p_chunk->get_sample_count(); t_size channel_count = p_chunk->get_channels(); t_size i; for(i=0;i<totalbars;i++) { double val = 0; t_size starti, endi, j; g_scale_value(sample_count, i, totalbars, starti, endi, m_scale == scale_logarithmic); for (j=starti;j<=endi; j++) { if (j < sample_count) { t_size k; for (k=0; k<channel_count; k++) val += p_data[j*channel_count + k]; } } val *= 1.0/( (endi-starti+1)*channel_count); val *= 0.80; if (val>1.0) val = 1.0; RECT r; r.left = 1 + i*m_bar_width; r.right = r.left + m_bar_width - m_bar_gap; r.bottom = rc_client->bottom ? rc_client->bottom-1 : 0; r.top = g_scale_value_single(1.0-val, rc_client->bottom, m_vertical_scale == scale_logarithmic); //pfc::rint32((1.0 - val) * (rc_client->bottom)); if (r.bottom>r.top) FillRect(dc,&r,br_foreground); } #else int spread = MulDiv(1, p_chunk->get_sample_count(), totalbars); if (spread < 1) spread = 1; double div = 1.0 / (double) p_chunk->get_channels(); unsigned left = 1; for(i=0;i<totalbars;i++) { unsigned right = left+MulDiv(1, rc_client->right-left-totalbars+i, totalbars-i); RECT r; r.left = left; r.right = right; double val = 0; unsigned start=MulDiv(i, p_chunk->get_sample_count()-spread, totalbars),co = 0; for (n=start;n<(start+spread);n++) { if (n<p_chunk->get_sample_count()) { co++; unsigned c; for(c=0;c<p_chunk->get_channels();c++) { val += ((p_chunk->get_data()[n*p_chunk->get_channels() + c])); } } } val *= div; if (co) val *= (1.0/(double)co); //val = log((val/2.0) + 1.0)*2.0; val *= 0.80; if (val>1.0) val = 1.0; r.bottom = rc_client->bottom > 0 ? rc_client->bottom-1 : 0; int top = (int)( (val) * (double(r.bottom)) + 0.5); top= r.bottom - top; // if (top==0) top++; /* for (;r.bottom-1>top; r.bottom-=2) { r.top = r.bottom-1; //FillRect(dc,&r,br_foreground);//LineToEx ? MoveToEx(dc, r.left, r.top, NULL); LineTo(dc, r.right, r.bottom); }*/ { RECT rc = {left, top, right, rc_client->bottom > 0 ? rc_client->bottom-1 : 0}; FillRect(dc,&rc,br_foreground); } left=right+1; } #endif int j; for (j=rc_client->bottom; j>rc_client->top; j-=2) { RECT rc = {0, j-1, rc_client->right, j}; FillRect(dc,&rc,br_background); } } } else { #if 1 //gdi_object_t<HPEN>::ptr_t pn = CreatePen(PS_SOLID, 1, cr_fore); //HPEN pn_old = SelectPen(dc, pn.get()); const audio_sample * p_data = p_chunk->get_data(); t_size sample_count = p_chunk->get_sample_count(); t_size channel_count = p_chunk->get_channels(); t_size i; for(i=0;i<(t_size)rc_client->right;i++) { double val = 0; //t_size starti = pfc::rint32(start), endi = pfc::rint32(end), j; t_size starti, endi, j; g_scale_value(sample_count, i, rc_client->right, starti, endi, m_scale == scale_logarithmic); for (j=starti;j<=endi; j++) { if (j < sample_count) { t_size k; for (k=0; k<channel_count; k++) val += p_data[j*channel_count + k]; } } val *= 1.0/( (endi-starti+1)*channel_count); val *= 0.80; if (val>1.0) val = 1.0; RECT r; r.left = i; r.right = i+1; r.bottom = rc_client->bottom; r.top = g_scale_value_single (1.0-val, rc_client->bottom, m_vertical_scale == scale_logarithmic);//pfc::rint32((1.0 - val) * (rc_client->bottom)); if (r.bottom>r.top) FillRect(dc,&r,br_foreground); //MoveToEx(dc, r.left, r.bottom, NULL); //LineTo(dc, r.left, r.top); } //SelectPen(dc, pn_old); #else int spread = MulDiv(1, p_chunk->get_sample_count(), rc_client->right); if (spread < 1) spread = 1; double div = 1.0 / (double) p_chunk->get_channels(); assert(rc_client->right>=0); for(i=0;i<(unsigned)rc_client->right;i++) { RECT r; r.left = i;//MulDiv(rc_client->right,n,data->spectrum_size+1); r.right = i+1;//MulDiv(rc_client->right,n+1,data->spectrum_size+1); // if (r.left < r.right) double val = 0; unsigned start=MulDiv(i, p_chunk->get_sample_count()-spread, rc_client->right),co = 0; for (n=start;n<(start+spread);n++) { if (n<p_chunk->get_sample_count()) { co++; unsigned c; for(c=0;c<p_chunk->get_channels();c++) { val += p_chunk->get_data()[n*p_chunk->get_channels() + c]; } } } val *= div; if (co) val *= (1.0/(double)co); //val = log((val/2.0) + 1.0) * 2.0; //close to a str8 line val *= 0.80; if (val>1.0) val = 1.0; r.bottom = rc_client->bottom; r.top = (int)((1.0 - val) * (rc_client->bottom)); /*double rt = sqrt(val); HBRUSH br_test = CreateSolidBrush(pfc::rint32((1.0-rt)*0xff + rt*(0x55))); FillRect(dc,&r,br_test); DeleteBrush(br_test);*/ FillRect(dc,&r,br_foreground); } #endif } } } ps.release(); }