Example #1
0
void can_project_micropolygon() {
    MeshPoint mp1(-10, -10, 100);
    MeshPoint mp2(10, -10, 100);
    MeshPoint mp3(-10, 10, 100);
    MeshPoint mp4(10, 10, 100);
    MicroPolygon poly;
    poly.a = mp1;
    poly.b = mp2;
    poly.c = mp3;
    poly.d = mp4;

    FrameBuffer fb(500, 500);
    fb.projectMicroPolygon(poly);

    ASSERT_EQUAL_FLOAT(poly.a.getX(), 206.699, 0.1);
    ASSERT_EQUAL_FLOAT(poly.a.getY(), 206.699, 0.1);

    ASSERT_EQUAL_FLOAT(poly.b.getX(), 293.301, 0.1);
    ASSERT_EQUAL_FLOAT(poly.b.getY(), 206.699, 0.1);

    ASSERT_EQUAL_FLOAT(poly.c.getX(), 206.699, 0.1);
    ASSERT_EQUAL_FLOAT(poly.c.getY(), 293.301, 0.1);

    ASSERT_EQUAL_FLOAT(poly.d.getX(), 293.301, 0.1);
    ASSERT_EQUAL_FLOAT(poly.d.getY(), 293.301, 0.1);
}
Example #2
0
void Media::updateTags(Format format){
    if(format == MP3){
        TagLib::MPEG::File mp3(filePath(MP3).c_str());
        TagLib::Tag *t = mp3.tag();
        if(!t) return;
        t->setTitle(TagLib::String(title(), TagLib::String::UTF8));
        t->setArtist(TagLib::String(artist().name(), TagLib::String::UTF8));
        mp3.save(TagLib::MPEG::File::ID3v1 | TagLib::MPEG::File::ID3v2);
    } else if(format == Vorbis) {
        TagLib::Ogg::Vorbis::File vorbis(filePath(Vorbis).c_str());
        TagLib::Tag *t = vorbis.tag();
        if(!t) return;
        t->setTitle(TagLib::String(title(), TagLib::String::UTF8));
        t->setArtist(TagLib::String(artist().name(), TagLib::String::UTF8));
        vorbis.save();
    }
}
Example #3
0
static void mp3_play_loop() {
  while (true) {
    Mp3Info mp3(play_queue.pop_front());
    {
      boost::mutex::scoped_lock lock(now_playing_mutex);
      now_playing = &mp3;
    }
    
    //FILE* fp = popen("mplayer -slave -really-quiet", "w");
    
    std::ostringstream command;
    command << "mplayer '" << mp3.filename << "'";
    system(command.str().c_str());
    
    {
      boost::mutex::scoped_lock lock(now_playing_mutex);
      now_playing = 0;
    }
  }
}
Example #4
0
void bounding_box_for_microPolygon_has_right_coords() {
    MeshPoint mp1(-10, -10, 100);
    MeshPoint mp2(10, -10, 100);
    MeshPoint mp3(-10, 10, 100);
    MeshPoint mp4(10, 10, 100);
    MicroPolygon poly;
    poly.a = mp1;
    poly.b = mp2;
    poly.c = mp3;
    poly.d = mp4;

    FrameBuffer fb(500, 500);
    fb.projectMicroPolygon(poly);

    BoundingBox box = poly.getBoundingBox();
    ASSERT_EQUAL_INT(box.X_start, 206);
    ASSERT_EQUAL_INT(box.Y_start, 206);
    ASSERT_EQUAL_INT(box.X_stop, 294);
    ASSERT_EQUAL_INT(box.Y_stop, 294);
}
Example #5
0
bool CUpnpBrowserGui::selectItem(std::string id)
{
	bool loop = true;
	bool endall = false;
	bool changed = true;
	bool rchanged = true;
	neutrino_msg_t      msg;
	neutrino_msg_data_t data;
	std::vector<UPnPEntry> *entries;
	unsigned int index, selected, dirnum;

	index=0;
	selected=0;
	dirnum=0;
	entries=NULL;

	while (loop)
	{
		updateTimes();
		if (rchanged)
		{
			if (entries)
				delete entries;
			entries=NULL;

			std::list<UPnPAttribute>attribs;
			std::list<UPnPAttribute>results;
			std::list<UPnPAttribute>::iterator i;
			std::stringstream sindex;
			std::stringstream scount;
			unsigned int returned = 0;

			bool rfound = false;
			bool nfound = false;
			bool tfound = false;

			sindex << index;
			scount << m_listmaxshow;

			attribs.push_back(UPnPAttribute("ObjectID", id));
			attribs.push_back(UPnPAttribute("BrowseFlag", "BrowseDirectChildren"));
			attribs.push_back(UPnPAttribute("Filter", "*"));
			attribs.push_back(UPnPAttribute("StartingIndex", sindex.str()));
			attribs.push_back(UPnPAttribute("RequestedCount", scount.str()));
			attribs.push_back(UPnPAttribute("SortCriteria", ""));
#if 0
			try
			{
				results=m_devices[m_selecteddevice].SendSOAP("urn:schemas-upnp-org:service:ContentDirectory:1", "Browse", attribs);
			}
			catch (std::runtime_error error)
			{
				ShowMsgUTF(LOCALE_MESSAGEBOX_INFO, error.what(), CMessageBox::mbrBack, CMessageBox::mbBack, "info.raw");
				if (entries)
					delete entries;
				return endall;
			}
#endif
			results=m_devices[m_selecteddevice].SendSOAP("urn:schemas-upnp-org:service:ContentDirectory:1", "Browse", attribs);
			for (i=results.begin(); i!=results.end(); i++)
			{
				if (i->first=="NumberReturned")
				{
					returned=atoi(i->second.c_str());
					nfound=true;
				}
				if (i->first=="TotalMatches")
				{
					dirnum=atoi(i->second.c_str());
					tfound=true;
				}
				if (i->first=="Result")
				{
					entries=decodeResult(i->second);
					rfound=true;
				}
			}
			if (!entries)
				return endall;
			if (!nfound || !tfound || !rfound)
			{
				delete entries;
				return endall;
			}
			if (returned != entries->size())
			{
				delete entries;
				return endall;
			}

			if (returned == 0)
			{
				delete entries;
				return endall;
			}
			rchanged=false;
			changed=true;
		}

		if (changed)
		{
			paintItem(entries, selected - index, dirnum - index, index);
			changed=false;
		}

		g_RCInput->getMsg(&msg, &data, 10); // 1 sec timeout to update play/stop state display
		neutrino_msg_t msg_repeatok = msg & ~CRCInput::RC_Repeat;

		if( msg == CRCInput::RC_timeout)
		{
			// nothing
		}
		else if(msg == CRCInput::RC_home)
		{
			loop=false;
			endall=true;
		}
		else if(msg == CRCInput::RC_left)
		{
			loop=false;
		}

		else if (msg_repeatok == CRCInput::RC_up && selected > 0)
		{
			selected--;
			if (selected < index)
			{
				index-=m_listmaxshow;
				rchanged=true;
			}
			changed=true;
		}

		else if(msg == CRCInput::RC_green && selected > 0)
		{
			if (index > 0)
			{
				index-=m_listmaxshow;
				selected-=m_listmaxshow;
				rchanged=true;
			}
			else
				selected=0;
			changed=true;
		}
		else if (msg_repeatok == CRCInput::RC_down && selected + 1 < dirnum)
		{
			selected++;
			if (selected + 1 > index + m_listmaxshow)
			{
				index+=m_listmaxshow;
				rchanged=true;
			}
			changed=true;
		}
		else if(msg == CRCInput::RC_red && selected + 1 < dirnum)
		{
			if (index < ((dirnum - 1) / m_listmaxshow) * m_listmaxshow)
			{
				index+=m_listmaxshow;
				selected+=m_listmaxshow;
				if (selected + 1 >= dirnum)
					selected=dirnum - 1;
				rchanged=true;
			}
			else
				selected=dirnum - 1;
			changed=true;
		}
		else if(msg == CRCInput::RC_right)
		{
			if ((*entries)[selected - index].isdir)
			{
				endall=selectItem((*entries)[selected - index].id);
				if (endall)
					loop=false;
			}
			changed=true;
		}
		else if(msg == CRCInput::RC_ok)
		{
			if (!(*entries)[selected - index].isdir)
			{
				m_folderplay = false;
				int preferred=(*entries)[selected - index].preferred;
				if (preferred != -1)
				{
					std::string protocol, prot, network, mime, additional;
					protocol=(*entries)[selected - index].resources[preferred].protocol;
					splitProtocol(protocol, prot, network, mime, additional);
					if (mime == "audio/mpeg")
					{
						CAudiofile mp3((*entries)[selected - index].resources[preferred].url, CFile::FILE_MP3);
						CAudioPlayer::getInstance()->play(&mp3, g_settings.audioplayer_highprio == 1);
					}
					else if (mime == "audio/x-vorbis+ogg")
					{
						CAudiofile mp3((*entries)[selected - index].resources[preferred].url, CFile::FILE_OGG);
						CAudioPlayer::getInstance()->play(&mp3, g_settings.audioplayer_highprio == 1);
					}
					m_playing_entry = (*entries)[selected - index];
#if 0
// #ifdef ENABLE_PICTUREVIEWER
					else if ((mime == "image/gif") || (mime == "image/jpeg"))
					{
						CPictureViewer *viewer = new CPictureViewer();
						bool loop=true;
						viewer->SetScaling((CPictureViewer::ScalingMode)g_settings.picviewer_scaling);
						viewer->SetVisible(g_settings.screen_StartX, g_settings.screen_EndX, g_settings.screen_StartY, g_settings.screen_EndY);

						if(g_settings.video_Format==1)
							viewer->SetAspectRatio(16.0/9);
						else if(g_settings.video_Format==0)
						{
							CControldClient cdc;
							cdc.setVideoFormat(CControldClient::VIDEOFORMAT_4_3);
							viewer->SetAspectRatio(4.0/3);
						}
						else
							viewer->SetAspectRatio(4.0/3);

						m_frameBuffer->setMode(720, 576, 16);
						m_frameBuffer->setTransparency(0);
						viewer->ShowImage((*entries)[selected - index].resources[preferred].url, true);
						while (loop)
						{
							g_RCInput->getMsg(&msg, &data, 10); // 1 sec timeout to update play/stop state display

							if( msg == CRCInput::RC_home)
								loop=false;
						}
						m_frameBuffer->setMode(720, 576, 8 * sizeof(fb_pixel_t));
						m_frameBuffer->setBlendLevel(g_settings.gtx_alpha1, g_settings.gtx_alpha2);
						m_frameBuffer->ClearFrameBuffer();
						delete viewer;
					}
// #endif
#endif
				}

			} 
Example #6
0
void CUpnpBrowserGui::playnext(void)
{
	while (true)
	{
		std::list<UPnPAttribute>attribs;
		std::list<UPnPAttribute>results;
		std::list<UPnPAttribute>::iterator i;
		std::stringstream sindex;
		std::vector<UPnPEntry> *entries = NULL;
		bool rfound = false;
		bool nfound = false;
		bool tfound = false;

		sindex << m_playid;
		attribs.push_back(UPnPAttribute("ObjectID", m_playfolder));
		attribs.push_back(UPnPAttribute("BrowseFlag", "BrowseDirectChildren"));
		attribs.push_back(UPnPAttribute("Filter", "*"));
		attribs.push_back(UPnPAttribute("StartingIndex", sindex.str()));
		attribs.push_back(UPnPAttribute("RequestedCount", "1"));
		attribs.push_back(UPnPAttribute("SortCriteria", ""));

#if 0
		try
		{
			results=m_devices[m_selecteddevice].SendSOAP("urn:schemas-upnp-org:service:ContentDirectory:1", "Browse", attribs);
		}
		catch (std::runtime_error error)
		{
			ShowMsgUTF(LOCALE_MESSAGEBOX_INFO, error.what(), CMessageBox::mbrBack, CMessageBox::mbBack, "info.raw");
			m_folderplay = false;
			return;
		}
#endif
		results=m_devices[m_selecteddevice].SendSOAP("urn:schemas-upnp-org:service:ContentDirectory:1", "Browse", attribs);
		for (i=results.begin(); i!=results.end(); i++)
		{
			if (i->first=="NumberReturned")
			{
				if (atoi(i->second.c_str()) != 1)
				{
					m_folderplay = false;
					return;
				}
				nfound=true;
			}
			if (i->first=="TotalMatches")
			{
				tfound=true;
			}
			if (i->first=="Result")
			{
				entries=decodeResult(i->second);
				rfound=true;
			}
		}
		m_playid++;
		if ((entries != NULL) && (!(*entries)[0].isdir))
		{
			int preferred=(*entries)[0].preferred;
			if (preferred != -1)
			{
				std::string protocol, prot, network, mime, additional;
				protocol=(*entries)[0].resources[preferred].protocol;
				splitProtocol(protocol, prot, network, mime, additional);
				if (mime == "audio/mpeg")
				{
					m_playing_entry = (*entries)[0];
					m_playing_entry_is_shown = false;
					CAudiofile mp3((*entries)[0].resources[preferred].url, CFile::FILE_MP3);
					CAudioPlayer::getInstance()->play(&mp3, g_settings.audioplayer_highprio == 1);
					return;
				}
				else if (mime == "audio/x-vorbis+ogg")
				{
					m_playing_entry = (*entries)[0];
					m_playing_entry_is_shown = false;
					CAudiofile mp3((*entries)[0].resources[preferred].url, CFile::FILE_OGG);
					CAudioPlayer::getInstance()->play(&mp3, g_settings.audioplayer_highprio == 1);
					return;
				}
			}
		} else {
			neutrino_msg_t      msg;
			neutrino_msg_data_t data;
			g_RCInput->getMsg(&msg, &data, 10); // 1 sec timeout to update play/stop state display

			if( msg == CRCInput::RC_home)
			{
				m_folderplay = false;
				break;
			}
		}
	}
}
Example #7
0
void player_thread(void* parameter)
{
	rt_err_t result;
	struct player_request request;

	while(1)
	{
		/* get request from message queue */
		result = rt_mq_recv(player_thread_mq, (void*)&request,
			sizeof(struct player_request), RT_WAITING_FOREVER);
		if (result == RT_EOK)
		{
			switch (request.type)
			{
			case PLAYER_REQUEST_PLAY_SINGLE_FILE:
				if ((strstr(request.fn, ".mp3") != RT_NULL) ||
					(strstr(request.fn, ".MP3") != RT_NULL))
				{
					is_playing = RT_TRUE;
					player_notify_play();

				    /* get music tag information */
					mp3(request.fn);

					player_notify_stop();
					is_playing = RT_FALSE;
				}
				else if ((strstr(request.fn, ".wav") != RT_NULL) ||
					(strstr(request.fn, ".WAV") != RT_NULL))
				{
					is_playing = RT_TRUE;
					player_notify_play();
					wav(request.fn);
					player_notify_stop();
					is_playing = RT_FALSE;
				}
				else if ((strstr(request.fn, "http://") == request.fn ||
					(strstr(request.fn, "HTTP://") == request.fn )))
				{
					is_playing = RT_TRUE;
					player_notify_play();
					ice_mp3(request.fn, request.station);
					/* notfiy net buffer worker to stop */
					net_buf_stop_job();
					player_notify_stop();
					is_playing = RT_FALSE;
				}
				else if (strstr(request.fn, "douban://") == request.fn)
				{
					is_playing = RT_TRUE;
					player_notify_play();
					douban_radio(request.fn, request.station);

					/* notfiy net buffer worker to stop */
					net_buf_stop_job();
					player_notify_stop();
					is_playing = RT_FALSE;
				}
				break;
			}
		}
	}
}
Example #8
0
NAMESPACE_CONVIMP3_START

bool Codec::encode( const char *in_file, const char *out_file )
{
    wave::Wave pcm( in_file );

    unsigned sample_rate    = pcm.get_samples_per_sec();
    unsigned byte_rate      = pcm.get_avg_bytes_per_sec();
    unsigned channels       = pcm.get_channels();

    std::ofstream mp3( out_file, std::ios_base::binary | std::ios_base::out  );

    const int PCM_SIZE = 8192;
    const int MP3_SIZE = 8192;

    unsigned offset = 0;

    std::vector<char> pcm_buffer;
    pcm_buffer.reserve( sizeof(short int) * PCM_SIZE * 2 );

    unsigned char mp3_buffer[MP3_SIZE];

    lameplus::LamePlus l;

    l.set_in_samplerate( sample_rate );
    l.set_brate( byte_rate );

    if( channels == 1 )
    {
        l.set_num_channels( 1 );
        l.set_mode( MONO );
    }
    else
    {
        l.set_num_channels( channels );
    }

    l.set_VBR( vbr_default );
    l.init_params();

    while( true )
    {
        int k = ( channels == 1 ) ? 1 : 2;

        unsigned size = PCM_SIZE * k * sizeof( short int );

        pcm.get_samples( offset, size, pcm_buffer );

        unsigned read = pcm_buffer.size();

        offset += read;

        if( read > 0 )
        {
            unsigned read_shorts = read / 2;  // need number of 'short int' read

            int write = 0;

            if( channels == 1 )
            {
                write = l.encode_buffer( reinterpret_cast<short int*>( &pcm_buffer[0] ), NULL, read_shorts, mp3_buffer, MP3_SIZE );
            }
            else
            {
                write = l.encode_buffer_interleaved( reinterpret_cast<short int*>( &pcm_buffer[0] ), read_shorts, mp3_buffer, MP3_SIZE );
            }

            pcm_buffer.clear();

            mp3.write( reinterpret_cast<char*>( mp3_buffer ) , write );
        }

        if( read < size )
        {
            int write = l.encode_flush( mp3_buffer, MP3_SIZE );

            mp3.write( reinterpret_cast<char*>( mp3_buffer ), write );

            break;
        }

    };

    return true;
}
Example #9
0
bool Codec::decode( const char *in_file, const char *out_file )
{
    std::ifstream mp3( in_file, std::ios_base::binary | std::ios_base::in );

    if( mp3.is_open() == false )
    {
        return false;
    }

    const int PCM_SIZE = 8192;
    const int MP3_SIZE = 8192;

    char pcm_buffer_l[ PCM_SIZE * sizeof(short int) ];
    char pcm_buffer_r[ PCM_SIZE * sizeof(short int) ];
    unsigned char mp3_buffer[MP3_SIZE];

    lameplus::LamePlus l;

    l.set_decode_only( 1 );

    if( l.init_params() == -1 )
        return false;

    lameplus::Hip       hip;

    bool got_header = false;

    wave::Wave res;

    int channels        = 0;

    while( true )
    {
        mp3.read( reinterpret_cast<char*>( mp3_buffer ), sizeof(char) * MP3_SIZE );

        int read = mp3.gcount();

        if( read <= 0 )
            break;

        int num_samples = 0;

        while( true )
        {
            if( got_header )
            {
                num_samples = hip.decode1(
                        mp3_buffer, read,
                        reinterpret_cast<short int*>( & pcm_buffer_l[0] ),
                        reinterpret_cast<short int*>( & pcm_buffer_r[0] ) );
            }
            else
            {
                lameplus::MP3Data   mp3data;

                num_samples = hip.decode1_headers(
                        mp3_buffer, read,
                        reinterpret_cast<short int*>( & pcm_buffer_l[0] ),
                        reinterpret_cast<short int*>( & pcm_buffer_r[0] ), mp3data );

                if( mp3data.is_header_parsed() )
                {
                    got_header = true;

                    channels        = mp3data.get_stereo();
                    int samplerate  = mp3data.get_samplerate();
                    int bitrate     = mp3data.get_bitrate() * 1000;

                    int bits_per_sample = bitrate / ( samplerate * channels );

                    bits_per_sample = 16;

                    res = wave::Wave( channels, samplerate, bits_per_sample );
                }
            }

            if( num_samples == 0 )
            {
                if( read > 0 )  // need more data to continue decoding
                {
                    read = 0;
                    continue;
                }
                break;
            }

            if( num_samples == -1 )
                throw std::logic_error( "Codec::decode(): decoding error" );

            if( got_header == false )
                throw std::logic_error( "Codec::decode(): got samples without header" );

            read    = 0;

            if( channels == 2 )
                res.append_samples( pcm_buffer_l, pcm_buffer_r, num_samples * sizeof( short int ) );
            else
                res.append_samples( pcm_buffer_l, num_samples * sizeof( short int ) );
        }

        if( mp3.fail() )
            break;
    }

    if( got_header == false )
        return false;

    res.save( out_file );

    return true;
}
Example #10
0
int main(){
	std::string mp3("/home/mhlzol004/Music/07 Bruno Mars - Natalie.mp3");
	idtag tagger(mp3);
}
void CUpnpBrowserGui::playAudio(std::string name, int type)
{
	CAudiofile mp3(name, (CFile::FileType) type);
	CAudioPlayer::getInstance()->play(&mp3, g_settings.audioplayer_highprio == 1);
}