void Nes_Emu::enable_sound( bool enabled ) { if ( enabled ) { for ( int i = channel_count(); i-- > 0; ) { Blip_Buffer* buf = sound_buf->channel( i ).center; int mapper_index = i - Nes_Apu::osc_count; if ( mapper_index < 0 ) emu.impl->apu.osc_output( i, buf ); else emu.mapper->set_channel_buf( mapper_index, buf ); } } else { emu.impl->apu.output( NULL ); for ( int i = channel_count() - Nes_Apu::osc_count; i-- > 0; ) emu.mapper->set_channel_buf( i, NULL ); } }
void Simple_Effects_Buffer::apply_config() { Effects_Buffer::config_t& c = Effects_Buffer::config(); c.enabled = config_.enabled; if ( c.enabled ) { c.delay [0] = 120; c.delay [1] = 122; c.feedback = config_.echo * 0.7f; c.treble = 0.6f - 0.3f * config_.echo; float sep = config_.stereo + 0.80f; if ( sep > 1.0f ) sep = 1.0f; c.side_chans [0].pan = -sep; c.side_chans [1].pan = +sep; for ( int i = channel_count(); --i >= 0; ) { chan_config_t& ch = Effects_Buffer::chan_config( i ); ch.pan = 0.0f; ch.surround = config_.surround; ch.echo = false; int const type = (channel_types() ? channel_types() [i] : 0); if ( !(type & noise_type) ) { int index = (type & type_index_mask) % 6 - 3; if ( index < 0 ) { index += 3; ch.surround = false; ch.echo = true; } if ( index >= 1 ) { ch.pan = config_.stereo; if ( index == 1 ) ch.pan = -ch.pan; } } else if ( type & 1 ) { ch.surround = false; } } } Effects_Buffer::apply_config(); }
blargg_err_t Nes_Emu::set_cart( Nes_Cart const* new_cart ) { close(); RETURN_ERR( auto_init() ); RETURN_ERR( emu.open( new_cart ) ); channel_count_ = Nes_Apu::osc_count + emu.mapper->channel_count(); RETURN_ERR( sound_buf->set_channel_count( channel_count() ) ); set_equalizer( equalizer_ ); enable_sound( true ); //reset(); return 0; }
SocketCanPump::~SocketCanPump() { size_t channels = channel_count(); for(size_t i=0; i<channels; ++i) { if(_is_virtual) { _deactivate_device(virtual_can_names[i]); } else { _deactivate_device(can_device_names[i]); } } }
bool SocketCanPump::initialize_devices(bool virtual_can) { _is_virtual = virtual_can; _nfds = 0; _can_initialized = false; size_t channels = channel_count(); if(channels > 4) { std::cout << "Unsupported number of channels for SocketCan (" << channels << ")!\n" << " -- Maximum size is 4" << std::endl; return false; } _sockets.resize(channels); for(size_t i=0; i<channels; ++i) { if(virtual_can) { if(!_initialize_device(virtual_can_names[i], i)) return false; } else { // Instruct the pcan device to operate at 1Mb/s int result = system( (std::string("echo \"i 0x0014 e\" > ") +pcan_device_names[i]).c_str()); if(result != 0) { perror("setting pcan to 1Mb/s"); fflush(stderr); } if(!_initialize_device(can_device_names[i], i)) return false; } } for(size_t i=0; i<_sockets.size(); ++i) { if(_sockets[i] > _nfds) _nfds = _sockets[i]; } ++_nfds; _can_initialized = true; return true; }
window::window_impl::window_impl(const display_cptr& in_display, const ::Window in_parent, const std::string& in_title, const math::vec2i& in_position, const math::vec2ui& in_size, const format_desc& in_sf) : surface::surface_impl(), _display(in_display->_impl->_display), _glx_extensions(in_display->_impl->_glx_extensions) { try { if (channel_count(in_sf._color_format) < 3) { std::ostringstream s; s << "window::window_impl::window_impl() <xlib>: " << "window pixel format must contain RGB or RGBA color format " << "(requested: " << format_string(in_sf._color_format) << ")."; //err() << log::fatal << s.str() << log::end; throw(std::runtime_error(s.str())); } std::stringstream fbc_err; _fb_config = util::framebuffer_config_selector::choose(in_display->_impl->_display, in_sf, util::framebuffer_config_selector::window_surface, _glx_extensions, fbc_err); if (0 == _fb_config) { std::ostringstream s; s << "window::window_impl::window_impl() <xlib>: " << "unable to select framebuffer config: " << fbc_err.str(); //err() << log::fatal << s.str() << log::end; throw(std::runtime_error(s.str())); } XVisualInfo* fb_visual = glXGetVisualFromFBConfig(in_display->_impl->_display, _fb_config); if (!fb_visual) { std::ostringstream s; s << "window::window_impl::window_impl() <xlib>: " << "unable to retrieve visual for framebuffer config " << _fb_config; //err() << log::fatal << s.str() << log::end; throw(std::runtime_error(s.str())); } XSetWindowAttributes wnd_attribs; Colormap wnd_color_map = XCreateColormap(in_display->_impl->_display, RootWindow(in_display->_impl->_display, fb_visual->screen), fb_visual->visual, AllocNone); wnd_attribs.colormap = wnd_color_map; wnd_attribs.background_pixmap = None; wnd_attribs.border_pixel = 0; wnd_attribs.event_mask = StructureNotifyMask; ::Window parent_wnd = RootWindow(in_display->_impl->_display, fb_visual->screen); if (0 != in_parent) { parent_wnd = in_parent; } _window_handle = ::XCreateWindow(in_display->_impl->_display, parent_wnd, in_position.x, in_position.y, in_size.x, in_size.y, 0, fb_visual->depth, InputOutput, fb_visual->visual, CWColormap, &wnd_attribs); if (!_window_handle) { std::ostringstream s; s << "window::window_impl::window_impl() <xlib>: " << "failed to create window."; //err() << log::fatal << s.str() << log::end; throw(std::runtime_error(s.str())); } _glx_window_handle = ::glXCreateWindow(in_display->_impl->_display, _fb_config, _window_handle, 0); if (!_glx_window_handle) { std::ostringstream s; s << "window::window_impl::window_impl() <xlib>: " << "failed to create glx window handle."; //err() << log::fatal << s.str() << log::end; throw(std::runtime_error(s.str())); } // set the drawable of the surface _drawable = _glx_window_handle; XFree(fb_visual); XStoreName(in_display->_impl->_display, _window_handle, in_title.c_str()); } catch (...) { cleanup(); throw; } }
scm::gl::texture_image_data_ptr load_image_2d(std::string const& filename, bool create_mips) { scm::scoped_ptr<fipImage> in_image(new fipImage); if (!in_image->load(filename.c_str())) { scm::gl::glerr() << scm::log::error << "texture_loader::load_image_2d(): " << "unable to open file: " << filename << scm::log::end; return scm::gl::texture_image_data_ptr(); } FREE_IMAGE_TYPE image_type = in_image->getImageType(); math::vec2ui image_size(in_image->getWidth(), in_image->getHeight()); scm::gl::data_format format = scm::gl::FORMAT_NULL; unsigned image_bit_count = in_image->getInfoHeader()->biBitCount; switch (image_type) { case FIT_BITMAP: { unsigned num_components = in_image->getBitsPerPixel() / 8; switch (num_components) { case 1: format = scm::gl::FORMAT_R_8; break; case 2: format = scm::gl::FORMAT_RG_8; break; case 3: format = scm::gl::FORMAT_BGR_8; break; case 4: format = scm::gl::FORMAT_BGRA_8; break; } } break; case FIT_INT16: format = scm::gl::FORMAT_R_16S; break; case FIT_UINT16: format = scm::gl::FORMAT_R_16; break; case FIT_RGB16: format = scm::gl::FORMAT_RGB_16; break; case FIT_RGBA16: format = scm::gl::FORMAT_RGBA_16; break; case FIT_INT32: break; case FIT_UINT32: break; case FIT_FLOAT: format = scm::gl::FORMAT_R_32F; break; case FIT_RGBF: format = scm::gl::FORMAT_RGB_32F; break; case FIT_RGBAF: format = scm::gl::FORMAT_RGBA_32F; break; } if (format == scm::gl::FORMAT_NULL) { scm::gl::glerr() << scm::log::error << "texture_loader::load_image_2d(): " << "unsupported color format: " << std::hex << in_image->getImageType() << scm::log::end; return scm::gl::texture_image_data_ptr(); } scm::gl::texture_image_data::level_vector mip_vec; unsigned num_mip_levels = 1; if (create_mips) { num_mip_levels = scm::gl::util::max_mip_levels(image_size); } for (unsigned i = 0; i < num_mip_levels; ++i) { scm::size_t cur_data_size = 0; math::vec2ui lev_size = scm::gl::util::mip_level_dimensions(image_size, i); if (i == 0) { lev_size = image_size; cur_data_size = image_size.x * image_size.y; cur_data_size *= channel_count(format); cur_data_size *= size_of_channel(format); } else { cur_data_size = lev_size.x * lev_size.y; cur_data_size *= channel_count(format); cur_data_size *= size_of_channel(format); if (FALSE == in_image->rescale(lev_size.x, lev_size.y, FILTER_LANCZOS3)) { scm::gl::glerr() << scm::log::error << "texture_loader::load_image_2d(): " << "unable to scale image (level: " << i << ", dim: " << lev_size << ")" << scm::log::end; return scm::gl::texture_image_data_ptr(); } if (in_image->getWidth() != lev_size.x || in_image->getHeight() != lev_size.y) { scm::gl::glerr() << scm::log::error << "texture_loader::load_image_2d(): " << "image dimensions changed after resamling (level: " << i << ", dim: " << lev_size << ", type: " << std::hex << in_image->getImageType() << ")" << scm::log::end; return scm::gl::texture_image_data_ptr(); } if (in_image->getInfoHeader()->biBitCount != image_bit_count) { scm::gl::glerr() << scm::log::error << "texture_loader::load_image_2d(): " << "image bitcount changed after resamling (level: " << i << ", bit_count: " << image_bit_count << ", img_bit_count: " << in_image->getInfoHeader()->biBitCount << ")" << scm::log::end; return scm::gl::texture_image_data_ptr(); } if (image_type != in_image->getImageType()) { scm::gl::glerr() << scm::log::error << "texture_loader::load_image_2d(): " << "image type changed after resamling (level: " << i << ", dim: " << lev_size << ", type: " << std::hex << in_image->getImageType() << ")" << scm::log::end; return scm::gl::texture_image_data_ptr(); } } scm::shared_array<unsigned char> cur_data(new unsigned char[cur_data_size]); size_t line_pitch = in_image->getScanWidth(); for (unsigned l = 0; l < lev_size.y; ++l) { size_t ls = static_cast<size_t>(lev_size.x) * size_of_format(format); uint8_t* s = reinterpret_cast<uint8_t*>(in_image->accessPixels()) + line_pitch * l; uint8_t* d = reinterpret_cast<uint8_t*>(cur_data.get()) + ls * l; std::memcpy(d, s, ls); } mip_vec.push_back({lev_size, cur_data}); } return boost::make_shared<scm::gl::texture_image_data>( scm::gl::texture_image_data::ORIGIN_LOWER_LEFT, format, mip_vec); }